Jump to content

[SOLVED] Selecting latest record from database


sted999

Recommended Posts

Hiya all.

What I am trying to do is select the last entry to my mysql table. I searched the internet and found an example, but this seems to be picking out the first entry. Can anybody suggest how to easily get the last(latest) entry. I have looked on the net but cant find anything?

 

Thanks.

 

<?php
$query = mysql_query("SELECT startTown,destinationTown FROM Journey ORDER BY date DESC LIMIT 1") 
                    or die(mysql_error());
?> 

try using ASC instead ..

 

No, that would list the data from past to present.

 

using LIMIT on a query will grab the first row every time ..

 

Yes, exactly.  The first row after it's been ordered by descending date.

 

@OP. you mean the most recent entry, correct?  Than the query you have is correct, something else is wrong.

Yes, it's pretty self explanatory.

 

ORDER BY date DESC LIMIT 1

 

=

 

order by date(column) in descending order only grab 1 record.

 

i read 'latest' as 'last' .. i need a break.

 

So did I, that's why I first thought it was ASC but then realized he meant "most recent".

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.