Display last 20 record

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
kevin7
Forum Commoner
Posts: 96
Joined: Fri May 21, 2004 6:54 am

Display last 20 record

Post by kevin7 »

how to display last 20 record in php?

can u show me the mysql query?
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Depends on the database and the table schema but basically, it's something like this:

Code: Select all

SELECT * FROM table ORDER BY id DESC LIMIT 20
kevin7
Forum Commoner
Posts: 96
Joined: Fri May 21, 2004 6:54 am

Post by kevin7 »

yes..~ it's work...

mysql hv the Top-N Analisys? (ROWNUM)
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

You mean

Code: Select all

select TOP 20 from table ...
?
No. MySQL uses LIMIT instead of this and can also be used to point out a starting row

Select 20 rows.

Code: Select all

select * from table LIMIT 20
Select 20 rows, starting at row 10.

Code: Select all

select * from table LIMIT 10, 20
There are some other special cases interesting to know about, and a good start to find info is here.
Post Reply