|
-
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'], 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("%04d", $currentSRNum);
Thank you
-
You can try the following:
Code:
$currentSR = 'JO'.$currentYMD . sprintf("04d",$currentSRNum);
-
I tried it and the output become:
first=JO120423001 // correct
second= JO1204232301 // wrong , it should be : JO120423002
Thank you
-
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));
-
 Originally Posted by WyCnet
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
-
Forum Rules
|
|
Bookmarks