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.

you can search about record set paging

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".

Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.