Most people seem to use LIMIT to get the rows for an individual page but I prefer to use mysql_dataseek() - you only need one query but with limit you need to do a second to get the total no of records. I'm not certain but I think dataseek is faster in many cases - can post the code for that if anyone's interested.
For the "page X of Y ... 1 | 2 | 3 etc" link, here's a function I use. You'll need to adapt it to show only ten pages within a list of hundreds, but this might help to get you started.
Feed it the total pages (usually get that from a mysql_num_rows) $max = max items per page, $link_id is the link to the next page of 10 or so MINUS the actual page id VAR (this will be tagged onto the end by the function), $page_choice is just which page in the 1 | 2 | 3 index you want to display now.
// displays "page X of Y .... 1 | 2 | 3 | etc "
function pageIndex($total_pages, $max, $link_id, $page_choice) {
/////////////////////////////////getting & printing the rows for this page
#echo "total_pages=$total_pages, max=$max, link_id=$link_id, page_choice=$page_choice<p>"; #debug line - uncomment to check VARs
$pages = ceil($total_pages / $max); #rounds up - so we get the total number of pages
# If page choice == 0 we choose the last page
# Also, if we delete the only item on a multi-page list of topics, or add a new item which takes us
# beyond the current page, page_choice supplied to this function is no longer valid
# ... so we get the (new) last page:
IF ($page_choice == 0 OR $page_choice > $pages) {
$page_choice = $pages;
} ELSEIF (is_null($page_choice)) {
$page_choice = 1; # auto sets to first page if null
}
////////////// creating the ".... X | Y | Z" html string ($output, echo'd below)
$x = 1;
IF ($pages > 1) { // if only one page, no need to create this
$output = " . . . . . ";
do {
IF ($x == $page_choice) {
$output .= "$x"." | "; // no link added for the current page being viewed
} ELSE { // adding the A HREF link - page choice ($x) is tagged onto the end of your $link_id..
// ..you'll need to adjust the next line to suit your own site nav system..
// ..you might put it all in the $link_id or you might need another bit before it
$output .="<A HREF=\"your path here" . $link_id . $x . "\">" . $x . "</A> | ";
}
$x++;
} while ($x <= $pages) ;
}
// define the rest of the output and tack the ".... X | Y | Z" html string on the end
$output = "<p class=\"your_style\">page " . $page_choice . " of " . $pages . $output . "</p>";
return "$output";
}
You might also want to show a 1 | 2 | 3 etc type link ie if you are looking at a topic list: you're not actually ON a list of posts page so you don't want the "page X of Y" bit. Can have a performance hit though - you'd be doing queries within a loop here. Anyway here it is:
// creates a 1 | 2 | 3 etc type link
function pages_xyz($total_pages, $max, $link_id) {
$pages = $total_pages / $max;
$pages = ceil($pages);
///////////creating the ".... X | Y | Z" html string ($output, echo'd below)
$x = 1;
IF ($pages > 1) {
$output = 'View page: ';
do {
$output .= "<A HREF=\"your path" . $link_id . $x . "\">" . $x . "</A> | ";
$x++;
} while ($x <= $pages) ;
} ELSEIF ($pages == 1) { // case for just one page
$output = "<A HREF=\"your path=" . $link_id . "1\"> View </A>";
} ELSE {
$output = null;
}
return $output;
}