note 71674 added to function.mysql-fetch-array

From: Date: Mon, 11 Dec 2006 16:29:39 +0000
Subject: note 71674 added to function.mysql-fetch-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-120502@lists.php.net to get a copy of this message
A simple function that returns the next auto index. I recommend you use a unique id and not a relative row index, but if the need arises, here's how to get that id before you INSERT without the error-prone MAX(id) approach. <?php function nextautoindex ($table) { $res=mysql_query("SHOW TABLE STATUS"); if (@mysql_num_rows($res)>0) { while ($row = @mysql_fetch_array($res, MYSQL_ASSOC)) { if ($table == $row["name"]) return $row["Auto_increment"]; }} return false; } /* Example usage: $newID = nextautoindex("user"); // output: 12 // Now you can insert multiple related records without guessing the id */ ?> ---- Server IP: 66.163.161.117 Probable Submitter: 74.132.11.223 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-array.php Edit -- https://master.php.net/note/edit/71674 Del: integrated -- https://master.php.net/note/delete/71674/integrated Del: useless -- https://master.php.net/note/delete/71674/useless Del: bad code -- https://master.php.net/note/delete/71674/bad+code Del: spam -- https://master.php.net/note/delete/71674/spam Del: non-english -- https://master.php.net/note/delete/71674/non-english Del: in docs -- https://master.php.net/note/delete/71674/in+docs Del: other reasons-- https://master.php.net/note/delete/71674 Reject -- https://master.php.net/note/reject/71674 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120502) next »