How to query for last 5 item entries

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
User avatar
edawson003
Forum Contributor
Posts: 133
Joined: Thu Aug 20, 2009 6:34 am
Location: Los Angeles, CA - USA

How to query for last 5 item entries

Post by edawson003 »

I have form on my site, where a user can enter and item into my sql table. I figured out how to display the last item entered by the user. How can I display the last 5 items entered?

Code: Select all

$lastresult = "SELECT itemname, itemid FROM Lib WHERE createdby = $id AND creatdt = (SELECT MAX(creatdt) FROM Lib WHERE createdby = $id) GROUP BY itemname, itemid";
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: How to query for last 5 item entries

Post by papa »

ORDER BY 'date' DESC LIMIT 5
User avatar
edawson003
Forum Contributor
Posts: 133
Joined: Thu Aug 20, 2009 6:34 am
Location: Los Angeles, CA - USA

Re: How to query for last 5 item entries

Post by edawson003 »

Bingo! That worked. Thx!
Post Reply