Page 1 of 1
controling the number of records returned from a query
Posted: Tue Nov 04, 2003 6:12 am
by alip
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 ??

Posted: Tue Nov 04, 2003 6:18 am
by jason
Which database are you using?
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 10
Posted: Tue Nov 04, 2003 6:41 am
by alip
yeah its mysql database, i can limit the number but i also need to be able to call the next 10 with a 'next' link and same for previous.
Posted: Tue Nov 04, 2003 6:55 am
by Manix
The proper way to limit your query is like this...
Code: Select all
SELECT * FROM $table_name WHERE $column = '$variable' LIMIT $start_from, $total_output
and without variables...
Code: Select all
SELECT * FROM table WHERE something = 'something' LIMIT 0, 25
that should work a little more efficiently!
//EDIT - Expanded on the answer!
Posted: Tue Nov 04, 2003 8:24 am
by infolock
so what you are saying, is you can call the query :
Code: Select all
SELECT * FROM table WHERE something = 'something' LIMIT 0, 25
and use
Code: Select all
SELECT * FROM table WHERE something = 'something' LIMIT 26, 50
and so on? if not, sorry just wondering myself on this one
Posted: Tue Nov 04, 2003 9:33 am
by evilMind
infolock wrote:so what you are saying, is you can call the query :
Code: Select all
SELECT * FROM table WHERE something = 'something' LIMIT 0, 25
and use
Code: Select all
SELECT * FROM table WHERE something = 'something' LIMIT 26, 50
and so on? if not, sorry just wondering myself on this one
Yes you can. It's keeping track of your start and display that is the trick across multiple pages.
Posted: Tue Nov 04, 2003 9:58 am
by infolock
awsome