Jump to content

How do I limit results from a MySQL to 10 per page


kpetsche20

Recommended Posts

$sql = "SELECT * FROM `table` WHERE `field` = 'value' LIMIT 10"

 

LIMIT is what you need :)

 

On another note -- if you want to do, say, the second 10, it's like this:

 

$sql = "SELECT * FROM `table` WHERE `field` = 'value' LIMIT 10, 10"

 

This means select rows, limit 10, start after the tenth, so you get 11, 12, 13, 14, 15, 16, 17, 18, 19 and 20.

Whatever you're getting from the database. If you don't want to filter it, you don't need that, and you can just use:

 

SELECT * FROM `table` LIMIT 10

 

All the value bit does is select from table WHERE the field (field name) is equal to the value (value name)

Im going to direct you to a very good tutorial on pagination:

 

http://www.phpfreaks.com/tutorial/basic-pagination

 

There's no point in us typing out another tutorial for you on the forums; so take a look at that one :)

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.