Can anyone shed some light on this ??
controling the number of records returned from a query
Moderator: General Moderators
controling the number of records returned from a query
Hi i am looking for the best way in which to limit the number of records returned from a query on my database. say my query returns 50 records when submitted, i would like to show 10 on the first page use a next button to show the next 10 and so on. A previous page button is also required to view the last 10 etc.
Can anyone shed some light on this ??
Can anyone shed some light on this ??
Which database are you using?
If you are using MySQL, I know you can use the LIMIT keyword. Such as:
If you are using MySQL, I know you can use the LIMIT keyword. Such as:
Code: Select all
SELECT * FROM table WHERE something = something LIMIT 10The proper way to limit your query is like this...
and without variables...
that should work a little more efficiently!
//EDIT - Expanded on the answer!
Code: Select all
SELECT * FROM $table_name WHERE $column = '$variable' LIMIT $start_from, $total_outputCode: Select all
SELECT * FROM table WHERE something = 'something' LIMIT 0, 25//EDIT - Expanded on the answer!
so what you are saying, is you can call the query :
and use
and so on? if not, sorry just wondering myself on this one
Code: Select all
SELECT * FROM table WHERE something = 'something' LIMIT 0, 25Code: Select all
SELECT * FROM table WHERE something = 'something' LIMIT 26, 50Yes you can. It's keeping track of your start and display that is the trick across multiple pages.infolock wrote:so what you are saying, is you can call the query :
and useCode: Select all
SELECT * FROM table WHERE something = 'something' LIMIT 0, 25and so on? if not, sorry just wondering myself on this oneCode: Select all
SELECT * FROM table WHERE something = 'something' LIMIT 26, 50