0

Hi,

I'm new in php and i need a code that show data from the database and limit it to only 5 results per page and if there are more than 5 results, the other results will be in page 2 and the other 11-15 results are in page 3 etc..

Please help me and can you provide an explanation to the code so that i can become more familiar with php..

Thanks for your help in advance.

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by diafol
0

The thing u are talking about is known as "Pagination". Its not much easy for the beginners though but you can have a search on google for it.
To limit the displayed records you can simply put this query:
"SELECT * FROM tablename LIMIT 10".
If you want records from 10-20 then you can achieve it by:
"SELECT * FROM tablename LIMIT 10,20".

Edited by rizvihaider72: n/a

0

If you want records from 10-20 then you can achieve it by:
"SELECT * FROM tablename LIMIT 10,20".

UNfortunately, this isn't right.

If you want records from 10-20 then you can achieve it by:
"SELECT * FROM tablename LIMIT 9,11"

The first number in the LIMIT x,y syntax refers to the offset (x). This means basically, how many records you want to skip before starting. So to start from the first records, you'd have this:

LIMIT 0, y (whatever y would be).

The second number in the LIMIT x,y syntax refers to the actual number of records (y) you want to return from the offset (x). SO:

LIMIT 3, 14

would give start at record 4 and return all records 4 to 17.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.