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.
Dividing results up over several pages
Moderator: General Moderators
-
Matt Phelps
- Forum Commoner
- Posts: 82
- Joined: Fri Jun 14, 2002 2:05 pm
take a look at http://www.mysql.com/doc/en/String_comp ... tions.html
and http://www.mysql.com/doc/en/SELECT.html (LIMIT clause)
and http://www.mysql.com/doc/en/SELECT.html (LIMIT clause)
I did something similar to this yesterday!
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.
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>");
?>* 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.