SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    auto generate stock number

    Hi..

    I started designing stock form.

    and I need to display automatically the stock number, the format is:yymmddxxx for example : 120323001

    I need to display that stock number in my textbox when I first visit in my form...

    Thank you so much...

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Look at the options on date().

    where are you storing the fact that the last one was say, 120323001 and the next should be 120323002?

  3. #3
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    I've notice in my code for autogenerate sr number, when no data was save in the database the sr number became 0001 the date did not display.

    Code:
    $sql = "SELECT sr_number FROM stock_requisition ORDER BY sr_date DESC LIMIT 1";
            $result = mysql_query($sql, $con);
            
            if (!$result) {
                echo 'failed'; 
                die();
            }
            $total = mysql_num_rows($result);
            if ($total <= 0) {
                $currentSRNum = 1;
                
            } 
            else {
    //------------------------------------------------------------------------------------------------------------------
                // Stock Number iteration.... 
                $row = mysql_fetch_assoc($result);
                
                $currentSRNum = (int)(substr($row['sr_number'],0,3));
                
                $currentSRYear  = (int)(substr($row['sr_number'],2,2));
                $currentSRMonth = (int)(substr($row['sr_number'],0,2));
                $currentSRNum = (int)(substr($row['sr_number'],6,4));
                $currentYear  = (int)(date('y'));
                $currentMonth = (int)(date('m'));
                $currentDay = (int)(date('d'));
    
                $currentSRYMD = substr($row['sr_number'], 0, 6);
                $currentYMD = date("ymd");
                if ($currentYMD > $currentSRYMD) 
                {  
                    $currentSRNum = 1;
                } 
                else 
                {  
                    $currentSRNum += 1;
                }                                           
            }
    //------------------------------------------------------------------------------------------------------------------         
            $yearMonth = date('ymd');    
            $currentSR = $currentYMD . sprintf("%04d", $currentSRNum);
    it works perfectly if theirs an sr number was already save in my database.

    Thank you


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •