Created
August 28, 2013 02:32
-
-
Save jamesnine/6361514 to your computer and use it in GitHub Desktop.
get the last id from a table; both the last known id and last auto_increment value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// next auto increment value | |
$result = mysql_query("SHOW TABLE STATUS LIKE 'tablename'"); | |
$row = mysql_fetch_array($result); | |
return $row['Auto_increment']; | |
// last (highest) id on table | |
$result = mysql_query("SELECT MAX(id) as lastid FROM `tablename`"); | |
$row = mysql_fetch_assoc($result); | |
return $row['lastid']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment