How do I display only the last row in a SQL db result?

A

Anonymous

Guest
This might be a complicated way of doing this but you could do two SQL queries. One to find the last unique id and then the next to search for the rest of the details under that ID number:

<?

// Replace the word "unique_id" with whatever your id label is for that column.
$query = "SELECT MAX(unique_id) FROM newsletters LIMIT 1";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result);

$query2 = "SELECT * FROM newsletters WHERE unique_id = '$row[unique_id]'";
$result2 = mysql_query ($query2);

?>

There may be a way of doing it using only one query but hey, this will work.
 
if you are using auto_increment right after an insert you can get the last inserted id by using

$id = mysql_insert_id();

then you will need to make a new query and use $id
 
Back
Top