Skip to content

Instantly share code, notes, and snippets.

@jamesnine
Created August 28, 2013 02:32
Show Gist options
  • Save jamesnine/6361514 to your computer and use it in GitHub Desktop.
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
// 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