How do I go about reading the very last row of a MySQL table? Thanks for your help.
Last line of MySQL
Oh, I want to mention that I do have an auto increment field, so maybe I could somehow select the highest number? Thanks for your help.
Have you tried:
$query = "SELECT *
FROM table_name
ORDER BY auto_increment_field ASC";
$result = msyql_query($query);
$rows = mysql_num_rows($result);
$query2 = "SELECT *
FROM table_name
WHERE id = '$rows'";
It's a work-around, but I'm pretty sure it works, unless you break your auto-increment.
You could also just query for the ID, then order it DESC, and limit it to 1 record (pulling the last record), and manipulate from there:
$lastrow = mysql_query("SELECT auto_increment_field FROM table_name ORDER BY auto_increment_field DESC LIMIT 1");
// $lastrow will now be the highest ID number in the database
Hope that helps.
~Brett
Originally posted by bpat1434
$lastrow = mysql_query("SELECT auto_increment_field FROM table_name ORDER BY auto_increment_field DESC LIMIT 1"); // $lastrow will now be the highest ID number in the database
~Brett [/B]
Shouldn't I just be able to echo $lastrow ? Or do I need to fetch or something. When I try to echo I get no output. Thanks!
Should be able to echo $lastrow