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
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.