www.webdeveloper.com
Results 1 to 5 of 5

Thread: issue in sprintf

  1. #1
    Join Date
    Oct 2011
    Posts
    350

    issue in sprintf

    Hi...

    how can I add jo in my autogenerate number :
    for example:
    from: 1204200001
    to: JO1204200001
    PHP Code:
    $sql "SELECT jo_number FROM job_order ORDER BY jo_date DESC LIMIT 1";
            
    $result mysql_query($sql$con);
            
            if (!
    $result) {
                echo 
    'failed'
                die();
            }
            
    $total mysql_num_rows($result);
            if (
    $total <= 0) {
                
    $currentSRNum 1;
                 
    $currentYear  = (int)(date('y'));
                
    $currentMonth = (int)(date('m'));
                
    $currentDay = (int)(date('d'));
               
                
    $currentSRYMD substr($row['jo_number'], 06);
                
    $currentYMD date("ymd");
                if (
    $currentYMD $currentSRYMD
                {  
                    
    $currentSRNum 1;
                } 
                else 
                {  
                    
    $currentSRNum += 1;
                }     
                 
            } 
            else {
    //------------------------------------------------------------------------------------------------------------------
                // Stock Number iteration.... 
                
    $row mysql_fetch_assoc($result);
                
                
    $currentSRNum = (int)(substr($row['jo_number'],0,3));
                
                
    $currentSRYear  = (int)(substr($row['jo_number'],2,2));
                
    $currentSRMonth = (int)(substr($row['jo_number'],0,2));
                
    $currentSRNum = (int)(substr($row['jo_number'],6,4));

                
    $currentYear  = (int)(date('y'));
                
    $currentMonth = (int)(date('m'));
                
    $currentDay = (int)(date('d'));
               
                
    $currentSRYMD substr($row['jo_number'], 06);
                
    $currentYMD date("ymd");
                if (
    $currentYMD $currentSRYMD
                {  
                    
    $currentSRNum 1;
                } 
                else 
                {  
                    
    $currentSRNum += 1;
                }                                           
            }
    //------------------------------------------------------------------------------------------------------------------         
            
    $yearMonth date('ymd');    
            
    $currentSR $currentYMD sprintf("%04d"$currentSRNum); 
    Thank you

  2. #2
    Join Date
    Feb 2012
    Location
    youTUBE
    Posts
    234
    You can try the following:
    Code:
            $currentSR = 'JO'.$currentYMD . sprintf("04d",$currentSRNum);

  3. #3
    Join Date
    Oct 2011
    Posts
    350
    I tried it and the output become:

    first=JO120423001 // correct
    second= JO1204232301 // wrong , it should be : JO120423002

    Thank you

  4. #4
    Join Date
    Feb 2012
    Location
    youTUBE
    Posts
    234

    I was led to believe...

    I would believe that the second item shows that a job number "2300" was found.
    Code:
    $currentSRNum = (int)(substr($row['jo_number'],6,4));

  5. #5
    Join Date
    Oct 2011
    Posts
    350
    Quote Originally Posted by WyCnet View Post
    I would believe that the second item shows that a job number "2300" was found.
    Code:
    $currentSRNum = (int)(substr($row['jo_number'],6,4));
    NO, the data of jo_number is the last digits which auto generate 0001, 0002 and so on.

    Thank you

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles