Hi
I have a mysql table with rows, I got those data by $row = mysql_fetch_Array($result), they can appear properly.
However, how can I just get the latest row and just show it?
If new a row of data inserted, it shows it only.
Thanks
Order by the date/time in reverse, then limit to 1 row. If you do not record the date/time, you can use the auto incremented id, but that may not be guaranteed to be in order of insertion.
some times you might be able to get LAST INSERT ID
by using function [man]mysql_insert_id/man http://docs.php.net/manual/en/function.mysql-insert-id.php But I am not sure, if this function always will return the value you want.
laserlight suggestion, to store the time of creation of each new row, is what we normally would use. This makes it easy!
"SELECT * FROM 'table' ORDER BY 'created_date' LIMIT 1" will return only 1 row, with first or last creation time I do not know if you should ORDER BY ASC or ORDER BY DESC ... 🙂 laserlight will tell you
If you had some timestamp column as has been mentioned, you would simply do an "ORDER BY date_col DESC LIMIT 1".
Thanks for help, ORDER BY date_col DESC LIMIT 1 does work