note 69569 added to function.mysql-insert-id

From: Date: Mon, 11 Sep 2006 09:59:43 +0000
Subject: note 69569 added to function.mysql-insert-id
Groups: php.notes 
Request: Send a blank email to php-notes+get-117009@lists.php.net to get a copy of this message
Hi, Below is a snippet for retriving the next insert id from a mysql table. It functions like the auto_increment option in phpMyAdmin. Hope you find it helpful. =] <?php 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'); ?> Cheers, Rudolf ---- Server IP: 203.194.196.146 Probable Submitter: 210.6.144.125 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-insert-id.php Edit -- https://master.php.net/note/edit/69569 Del: integrated -- https://master.php.net/note/delete/69569/integrated Del: useless -- https://master.php.net/note/delete/69569/useless Del: bad code -- https://master.php.net/note/delete/69569/bad+code Del: spam -- https://master.php.net/note/delete/69569/spam Del: non-english -- https://master.php.net/note/delete/69569/non-english Del: in docs -- https://master.php.net/note/delete/69569/in+docs Del: other reasons-- https://master.php.net/note/delete/69569 Reject -- https://master.php.net/note/reject/69569 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#117009) next »