sorting limit

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
Z3r0Tol3ranc3
Forum Newbie
Posts: 7
Joined: Mon Jul 01, 2002 11:44 am

sorting limit

Post by Z3r0Tol3ranc3 »

hi, i'm coding a news page with a full newspage and an other page that only show the last 3 items, my question, HOW? i can't get it sorted right because i simply dont know how, this is the query call:

Code: Select all

$query="SELECT * FROM nieuwtjes ORDER BY id DESC LIMIT 0 , 100";
what should i add to it that only the 3 last news items are shown? MAX 3 doesn't work :)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You don't say what you want it ordered by, currently it is being ordered by id, which is what the

Code: Select all

ORDER BY id DESC
bit is - order by id in descending order.

Code: Select all

LIMIT 0, 100
Describes how many items should be returned. To get the first three results:

Code: Select all

LIMIT 3
Have a look at the mysql documentation on SELECT to find out more:
http://www.mysql.com/doc/S/E/SELECT.html

Mac
Z3r0Tol3ranc3
Forum Newbie
Posts: 7
Joined: Mon Jul 01, 2002 11:44 am

Post by Z3r0Tol3ranc3 »

ok thx dude, that helped me out,
thx again
Post Reply