Jump to content

Archived

This topic is now archived and is closed to further replies.

dharm

how do i add to a ID number

Recommended Posts

Hi I have this script that calls the most recent ID number from mysql using last_insert_id() but I would like to add 1 to make a new ID. For some reason when I try to add 1 to my six digit ID it returns less numbers.. for example ID is 000123. if I add 1 to 000123 I get 124. Im not sure if im using the right method.. Here is the code, any help would be much appreciated.

[code]$query1 = "Select *, last_insert_id() from ".$DBprefix."client_info ORDER BY `id` DESC LIMIT 1";
$result = mysql_query($query1);
if (mysql_errno())
{
die("<br>" . mysql_errno() .": ".mysql_error()."<br>");
}
$row = mysql_fetch_row($result);
if (mysql_errno())
{
die("<br>" . mysql_errno() .": ".mysql_error()."<br>");
}
$newid = $row[0];
echo "<br>Assigned ID: $newid"; // this echos 000123

$newid++;

echo "$newid";  // this echos 124[/code]

Thx.

Share this post


Link to post
Share on other sites
[code]echo sprintf("%06d", $newid);  // this echos 000124[/code]

[a href=\"http://www.php.net/sprintf\" target=\"_blank\"]http://www.php.net/sprintf[/a]

Share this post


Link to post
Share on other sites
thank you poirot!... Does anyone know how i could also check for the ID code within another table aswell as client_info.. whas the best way to structure this? thx. [quote]thank you!... Does anyone know how i could also check for the ID code within another table aswell as client_info.. whas the best way to structure this? thx.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.