note 64503 added to function.microtime

From: Date: Mon, 17 Apr 2006 01:14:34 +0000
Subject: note 64503 added to function.microtime
Groups: php.notes 
Request: Send a blank email to php-notes+get-108298@lists.php.net to get a copy of this message
It's pretty easy to know the value before you insert the new row. You can either select the last row with: <?php // replace id with whatever you named your auto_increment field $query = 'SELECT id FROM table_in_question ORDER BY id DESC LIMIT 0, 1'; if(!$sql = mysql_query($query)) { die('Query failed near ' . __FILE__ . ':' . __LINE__); } list($id) = mysql_fetch_row($sql); $next_id = $id + 1; ?> And assume there are no breaks in the table. If your application can safely ensure this, this is the simplest way to do it. Or, if your application cannot ensure this, you can use this: <?php $query = 'SHOW TABLE STATUS LIKE \'table_in_question\''; if(!$sql = mysql_query($query)) { die('Query failed near ' . __FILE__ . ':' . __LINE__); } $row = mysql_fetch_row($sql); $next_autoincrement = $row[10]; /* ----------------- OR --------------------- */ $row = mysql_fetch_array($sql); $next_autoincrement = $row['Auto_increment']; ?> Both work quite well. I use the first in my game for certain insertions. ---- Server IP: 64.71.164.2 Probable Submitter: 68.32.182.151 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.microtime.php Edit -- http://master.php.net/note/edit/64503 Del: integrated -- http://master.php.net/note/delete/64503/integrated Del: useless -- http://master.php.net/note/delete/64503/useless Del: bad code -- http://master.php.net/note/delete/64503/bad+code Del: spam -- http://master.php.net/note/delete/64503/spam Del: non-english -- http://master.php.net/note/delete/64503/non-english Del: in docs -- http://master.php.net/note/delete/64503/in+docs Del: other reasons-- http://master.php.net/note/delete/64503 Reject -- http://master.php.net/note/reject/64503 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#108298) next »