Page 1 of 1
Dividing results up over several pages
Posted: Wed Oct 02, 2002 5:40 am
by Matt Phelps
I have a list of name in my database and I want to print them out over several pages rather than just one long page. How do I get the results of my mySQL query to start on a new page after - say - 10 names? And how about ordering them alphabetically? As in all the 'A's on one page and all the 'B's on another etc..
Can anyone explain to me how to achieve this? I have done a search for answers but I've not understood the answers that people have given.
Posted: Wed Oct 02, 2002 8:15 am
by volka
Posted: Fri Oct 04, 2002 9:16 am
by f1nutter
I did something similar to this yesterday!
Code: Select all
<?php
$records = 10; // Number of records per page
$start = $_GETї"start"]; // Get "start" value from address line
if ($start == NULL) // No address line variable
{
$start = 0; // Default value
}
$query = "SELECT name FROM table LIMIT " .$start. ", " .$records;
// YOUR CODE HERE
// Run the query and display results
// Add number of records per page to starting value to get records for next page
$next = $start + $records;
print("<form method="GET" action="?$next">);
print("<input type="submit" value="Next">);
print("</form>");
?>
So, what do we have here?
* Get the row number to start displaying from, from the address line
* Set to 0 to begin
* Run query, limiting the output to 10 rows at a time.
* Add a form button to get the next page of records
* Address line =
http://www.somewhere.com/page.php
* Press next
* Address line =
http://www.somewhere.com/page.php?start=10
* etc.