...

View Full Version : issue in sprintf



newphpcoder
04-20-2012, 08:37 AM
Hi...

how can I add jo in my autogenerate number :
for example:
from: 1204200001
to: JO1204200001


$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

Fou-Lu
04-20-2012, 03:45 PM
JO%04d would work.

newphpcoder
04-23-2012, 02:53 AM
JO%04d would work.

I tried this but the output is:

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

Thank you

Fou-Lu
04-23-2012, 03:42 AM
That hasn't a thing to do with sprintf, that will be $currentSRNum, so something is wrong with your data or generating of it.
Since you have no looping in place here, I don't know what you are referring to by the second one.

newphpcoder
04-23-2012, 03:50 AM
That hasn't a thing to do with sprintf, that will be $currentSRNum, so something is wrong with your data or generating of it.
Since you have no looping in place here, I don't know what you are referring to by the second one.

I was referring on the $currentSRNum.

Thank you



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum