Return to Snippet

Revision: 3050
at May 27, 2007 10:32 by llbbl


Initial Code
function mysql_autoid($id,$table){
    $query = 'SELECT MAX('.$id.') AS last_id FROM '.$table;
    $result = mysql_query($query);
    $result = mysql_fetch_array($result);
    return $result[last_id]+1;
}

// usage mysql_autoid('nID','news');
// for use with fields that don't have auto_increment enabled
// otherwise just use $last_id = mysql_insert_id(); following a successful INSERT

Initial URL

                                

Initial Description

                                

Initial Title
Auto Increment Function

Initial Tags
mysql, php, textmate

Initial Language
HTML