Auto Increment Function


/ Published in: HTML
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function mysql_autoid($id,$table){
  2. $query = 'SELECT MAX('.$id.') AS last_id FROM '.$table;
  3. $result = mysql_query($query);
  4. $result = mysql_fetch_array($result);
  5. return $result[last_id]+1;
  6. }
  7.  
  8. // usage mysql_autoid('nID','news');
  9. // for use with fields that don't have auto_increment enabled
  10. // otherwise just use $last_id = mysql_insert_id(); following a successful INSERT
  11.  

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.