Page 1 of 1

Display last 20 record

Posted: Mon May 31, 2004 7:46 am
by kevin7
how to display last 20 record in php?

can u show me the mysql query?

Posted: Mon May 31, 2004 8:09 am
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

Posted: Mon May 31, 2004 8:26 am
by kevin7
yes..~ it's work...

mysql hv the Top-N Analisys? (ROWNUM)

Posted: Mon May 31, 2004 11:01 am
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.