Jump to content

add letter JO on the autoincrement data produce


newphpcoder
 Share

Recommended Posts

Hi..I have code for auto increment of JO Number, now it display:120504001by using this code:

<?php  $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'], 0, 6);		    $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'], 0, 6);		    $currentYMD = date("ymd");		    if ($currentYMD > $currentSRYMD)		    { 			    $currentSRNum = 1;		    }		    else		    { 			    $currentSRNum += 1;		    }										  	    }//------------------------------------------------------------------------------------------------------------------			    $yearMonth = date('ymd');   	    $currentSR = $currentYMD . sprintf("%03d", $currentSRNum);?>

now I want it to be:JO120504001JO120504002JO120504003JO120504004JO120505001JO120504002JO120504003Any help is highly appreciated.Thank you so much

Link to comment
Share on other sites

if you want php to print it you can prepend "JO" before it before printing echo "JO{$row['jo_num']}";

Edited by birbal
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...