newphpcoder Posted May 4, 2012 Share Posted May 4, 2012 Hi.. I have code for auto increment of JO Number, now it display: 120504001 by 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: JO120504001 JO120504002 JO120504003 JO120504004 JO120505001 JO120504002 JO120504003 Any help is highly appreciated. Thank you so much Quote Link to comment https://forums.phpfreaks.com/topic/262048-add-letter-jo-on-the-autoincrement-numbers/ Share on other sites More sharing options...
Drummin Posted May 4, 2012 Share Posted May 4, 2012 And what do you get if you add this echo "JO$currentSRNum"; Quote Link to comment https://forums.phpfreaks.com/topic/262048-add-letter-jo-on-the-autoincrement-numbers/#findComment-1342899 Share on other sites More sharing options...
newphpcoder Posted May 4, 2012 Author Share Posted May 4, 2012 I tried it and the output is: JO1 Thank you Quote Link to comment https://forums.phpfreaks.com/topic/262048-add-letter-jo-on-the-autoincrement-numbers/#findComment-1342901 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.