PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
in the above peace of code i am trying to update the next row but let assume tht if there is no AddID 2 (if id 2 and 3 are been deleted by some one and the next id present in db is 4) what will hapen. is there any method that can tell about the next row's ID....
$query = "SELECT something FROM table order BY id DESC LIMIT 1";
$result = mysql_query($query) or die (mysql_error());
// then add one onto returned result
$query = "SELECT something FROM table";
$result = mysql_query($query) or die (mysql_error());
$num_rows = mysql_num_rows($result);
$nextID = $num_rows++;
Now here is a point if last id was 23 and by $id ++ it will move to 24th if 24th is deleted or not present what will hapen does it has tendency to move to 25th????
$query = "SELECT something FROM table order BY id DESC LIMIT 1";
$result = mysql_query($query) or die (mysql_error());
// then add one onto returned result
you can reset the autoincrementing number back to there if you wish but by default it will skip it, i have employed a function many times that always checks ID and deletes any "blanks"
malcolmboston wrote:you can reset the autoincrementing number back to there if you wish but by default it will skip it, i have employed a function many times that always checks ID and deletes any "blanks"
You mean it will skip the the deleted and will move to next number (for example if 24th is deleted it will automatically move to 25 or if 25 is not there it will move to 26th wot so ever....)
say you have a table where your upto ID 7
you use ID 8 then delete it
it will now use ID 9 even thought ID 8 is avalailable
you can stop this as i mentioned earlier but i dont hjave my function available to me right now and cannot remember the name of it, its a MySQL function i know that much