Forum Moderators: coopster
I am very new to php (three weeks) and i am trying to do a search database etc...
im doing ok ( i think...lol)
I am getting my results to show in the order i want now, but i want my results to show a max of 10 on each page... the problem is I dont know how to only show 10 results on one page and to have a next button that will show the next 10 and so on and so on.
please please could someone help as it is doig my head in! ive tried alsorts of examples and it just messes things up... can anyone edit my code and document it to show me how its done?
< code snipped, please see Posting Guidelines [webmasterworld.com] >
[edited by: coopster at 3:17 pm (utc) on Feb. 28, 2006]
[edit reason] snipped unnecessary code [/edit]
Any pagination will involve two things ...
The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be non-negative integer constants (except when using prepared statements).
With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):
SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15
With one argument, the value specifies the number of rows to return from the beginning of the result set:
SELECT * FROM tbl LIMIT 5; # Retrieve first 5 rows
In other words, LIMIT row_count is equivalent to LIMIT 0, row_count.
Knowing this, you can use a counter in your process to set a link at the base of each page to set a "Next" variable that you could use when a user clicks on it. You rebuild the page with the new
offet, row_countin the LIMIT clause of your SELECT statement.
Give it a shot, if you are stuck or need some more information, perhaps this thread and the corresponding links will help you understand php pagination [webmasterworld.com].