Jump to content

how do i add to a ID number


dharm

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.
Link to comment
https://forums.phpfreaks.com/topic/12240-how-do-i-add-to-a-id-number/
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.

Archived

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

×
×
  • Create New...

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.