Yetimwork Beyene
Yetimwork Beyene

Reputation: 2337

How to get a certain number sequence of rows using mysql and PHP?

How can I get a certain number sequence of rows using mysql and PHP?

For example, I have a table call test1 and need to get first 10 rows (0-9), followed by the next sequence of rows (10-19) with another mysql/php request and so on... In other words, I need to get only 10 rows at a time per mysql php request?

Upvotes: 1

Views: 173

Answers (1)

Tudor Constantin
Tudor Constantin

Reputation: 26861

Use the LIMIT clause in your SQL queries.

What you want is called pagination - each batch of records is considered a page. You have to somehow (through session, or in the link the user clicks) have to hold account for your current page and request for the next like:

SELECT .... LIMIT (page_no * batchsize), batchsize

This article has some clear examples on how to do that. I hope this helps.

PS: please increase your accept ratio - it's the single way of showing your thanks to people who bother help you

Upvotes: 1

Related Questions