Only Show Lasat Record

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
CoolAsCarlito
Forum Contributor
Posts: 192
Joined: Sat May 31, 2008 3:27 pm
Contact:

Only Show Lasat Record

Post 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.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Only Show Lasat Record

Post 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.
Post Reply