dharm Posted June 17, 2006 Share Posted June 17, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/12240-how-do-i-add-to-a-id-number/ Share on other sites More sharing options...
poirot Posted June 17, 2006 Share Posted June 17, 2006 [code]echo sprintf("%06d", $newid); // this echos 000124[/code][a href=\"http://www.php.net/sprintf\" target=\"_blank\"]http://www.php.net/sprintf[/a] Quote Link to comment https://forums.phpfreaks.com/topic/12240-how-do-i-add-to-a-id-number/#findComment-46661 Share on other sites More sharing options...
dharm Posted June 17, 2006 Author Share Posted June 17, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/12240-how-do-i-add-to-a-id-number/#findComment-46692 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.