note 64503 deleted from function.microtime by tularis

From: Date: Sun, 22 Jun 2008 12:10:26 +0000
Subject: note 64503 deleted from function.microtime by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-140684@lists.php.net to get a copy of this message
Note Submitter: floppie at quadra-techservices dot com ---- 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.

« previous php.notes (#140684) next »