Page 1 of 1

Only Show Lasat Record

Posted: Wed Aug 13, 2008 12:04 pm
by CoolAsCarlito
I have this bit of code:

$query = "SELECT * FROM shows ";

but I want it to just grab the last record created in that table and if no record is present then to type a mesage saying "No shows available for results" or something like that.

Re: Only Show Lasat Record

Posted: Wed Aug 13, 2008 12:12 pm
by jayshields
Have you got a field in the database which could define what order the records were created? For example, an auto-incremented ID or a date inserted field?

I assume you have, and in that case, use something like this:

Code: Select all

SELECT * FROM `table` ORDER BY `id` DESC LIMIT 1
Also, please use [ code ] [ /code ] tags in your posts.