Jump to content

get mysql row number for new row


scott212

Recommended Posts

If you've just inserted it, then you can do this:
[code]
<?php
$query=mysql_query("SELECT COUNT(*) FROM table_name");
$result=mysql_result($query,0);
echo $result;
?>
[/code]
As it'll be the last row, just find out how many rows there are.  If you want to do it at a later time, then this won't work because other rows may have been inserted.  You could use:
[code]
<?php
$query=mysql_query("SELECT id FROM table_name WHERE something=$something");
$result=mysql_fetch_assoc($query);
echo $result;
?>
[/code]
This'll work all the time, but only if you have one of the pieces of data stored somewhere, like in a SESSION variable.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.