August 12th, 1999, 09:58 PM
i want search results to be limited to 10 records per page.
say, if a search on a database return 95 records, i want the results to be formatted to 10 pages.
how do i do that ?
August 14th, 1999, 04:17 AM
select * from table_name limit 10
and for next page:
select * from table_name limit 10, 10
August 16th, 1999, 12:11 AM
What you see in the last example is SQL's LIMIT and OFFSET functions. The syntax above is for MySQL. Other SQL DB's format it slightly differently:
select * from table_name limit 10 offset 10
Basically your SQL engine does the query and then returns only 10 records (the limit) starting with the 10th record in the query result (the offset).
You can then display the entire query result on your page and know that it'll only have 10 lines. You'll need to set up a system for tracking the offset so you can create NEXT and PREVIOUS functions that simply +10 or -10 the offset and display the new results on a fresh page.