Getting the last record in a mysql table
| From: | hugh danaher | Date: | Fri, 18 Jan 2002 05:37:28 +0000 |
| Subject: | Getting the last record in a mysql table | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-81029@lists.php.net to get a copy of this message | ||
Help!
I thought this would be easy but it ain't. What I want is the id number of the last record in
a table. I've tried a number of variations to the following but am getting no where! Any help
will be greatly appreciated.
Hugh
$results=mysql_query(" SELECT last_insert_id() FROM MY_TABLE ");
$row=mysql_fetch_assoc($results);
while ($row=mysql_fetch_row($results))
{
print "<tr>";
foreach($row as $field)
{
if ($field=="")
{
$field=" ";
}
print "<td align=center><h5>".$field."</h5></td>";
}
print "</tr>";
}
print "</table></td></tr></table>";