Forum Moderators: coopster

Message Too Old, No Replies

pulling "most recent" data from mySQL

pulling "most recent" data from mySQL

         

adjustreality

5:56 pm on Dec 6, 2008 (gmt 0)

10+ Year Member



Need to pull an ID number out of a table, I'm modifying a simple guestbook to display "amount of petitions" signed.

I figured pulling the most recent (via date maybe?) ID would be the easiest way since its a +1 action every time someone signs it.

any ideas?

Pico_Train

5:30 am on Dec 7, 2008 (gmt 0)

10+ Year Member



Add these to your query at the end.

ORDER BY date ASC or ORDER BY date DESC - 1 or th other should do it, I get confused with those two ASC and DESC.

You can also do the same with the IDs. ORDER BY ID ASC or ORDER BY ID DESC.

I think desc will give you the latest ID inserted in MySQL.

Anyango

6:25 am on Dec 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ASC is Ascending Order
and DESC is Descending Order

So if you order a field DESC that means latest (highest/ biggest value ) will be returned first and smallest will be last and its Opposite in ASC case, in ASC smallest will be returned first and largest last.

if you have a field for ID, simply append this to your query

ORDER BY ID DESC

[edited by: Anyango at 6:26 am (utc) on Dec. 7, 2008]

Pico_Train

8:25 am on Dec 7, 2008 (gmt 0)

10+ Year Member



That's the ticket!