hello
i have been using a php paging script for many years that i think i got from a zend tutorial however this tutorial or script im using doenst allow for many pages
for example
PREV 10 | [1] | [2] |[1] | [2] |[1] | [2] |[1] | [2] |[1] | [2] |[1] | [2] |[1] | [2] | NEXT 10
I want to have the option: (so I dont have the problem with pages cutting off)
PREV 10 | [1] | [2] |[1] | [2] |[1] |... | NEXT 10
I can get another php class that could do this but would rather want to understand how to do this, here is my code (sorry that its soo long)
function Paging($globalDisplay) {
/***************************
DISPLAY PAGINATION
*************************/
global $totalRows;
global $limit;
global $whatDisplay;
if ($totalRows > 0) {
$whatDisplay = '<table cellpadding="5" cellspacing="0" border=0 ><tr valign="top">';
if($_GET['page'] != 1){
$pageprev = $_GET['page'] -1;
// Fancy way of subtracting 1 from $page
$whatDisplay .= "<td><a href=\"$_SERVER[PHP_SELF]?page=$pageprev&category=$_GET[category]\" class='articles_red'>PREV".$limit."</a></span></td> ";
/* Tip: It is a good idea NOT to use $PHP_SELF in this link. It may work,
but to be 99.9% sure that it will, be sure to use the actual name of the file
this script will be running on. Also, the adds a space to the end of
PREV, and gives some room between the numbers. */
} else
$whatDisplay .= "<td>PREV ".$limit." </span></td>";
// If we're on page 1, PREV is not a link
$numofpages = $totalRows/ $limit;
/* We divide our total amount of rows (for example 102) by the limit (25). This
will yield 4.08, which we can round down to 4. In the next few lines, we'll
create 4 pages, and then check to see if we have extra rows remaining for a 5th
page. */
for($i = 1; $i <= $numofpages; $i++){
/* This for loop will add 1 to $i at the end of each pass until $i is greater
than $totalRows (4.08). */
if($i == $_GET['page']){
$whatDisplay.= '<td bgcolor="#f1f1f1">['.$i."] </td>";
} else{
$whatDisplay .= "<td><a href=\"$_SERVER[PHP_SELF]?page=$i&category=$_GET[category]\" class='articles_red'>[$i]</a> </td>";
}
/* This if statement will not make the current page number available in
link form. It will, however, make all other pages available in link form. */
} // This ends the for loop
if(( $totalRows % $limit) != 0){
/* The above statement is the key to knowing if there are remainders, and it's
all because of the %. In PHP, C++, and other languages, the % is known as a
Modulus. It returns the remainder after dividing two numbers. If there is no
remainder, it returns zero. In our example, it will return 0.8 */
if($i == $_GET['page']){
$whatDisplay .= '<td>['.$i."]</td> ";
}else{
$whatDisplay .="<td><a href=\"$_SERVER[PHP_SELF]?page=$i&category=$_GET[category]\" class='articles_red'>[$i]</a> </td>";
}
/* This is the exact statement that turns pages into link form that is used
above */
} // Ends the if statement
if ($totalRows - ($limit * $_GET['page']) > 0) {
$pagenext = abs($_GET['page']) +1;
// Fancy way of adding 1 to page
$whatDisplay .="<td><a href=\"$_SERVER[PHP_SELF]?page=$pagenext&category=$_GET[category]\" class='articles_red'>NEXT".$limit."</a></td>";
/* Since there are pages remaining, this outputs NEXT in link form. */
} else {
$whatDisplay.= "<td>NEXT ".$limit. ' </td>';
/* If we're on the last page possible, NEXT will NOT be displayed in link
form. */
}
$whatDisplay.= '</tr></table>';
}
//return $whatDisplay;
}