PHP Classes

Excellent Class!!!!

Recommend this page to a friend!

      A simple pagination using MySQL  >  All threads  >  Excellent Class!!!!  >  (Un) Subscribe thread alerts  
Subject:Excellent Class!!!!
Summary:Best one I've found yet, having been searching all morning
Messages:1
Author:Bill Dawes
Date:2009-04-24 22:44:48
 

  1. Excellent Class!!!!   Reply   Report abuse  
Picture of Bill Dawes Bill Dawes - 2009-04-24 22:44:48
Nice work, very neat little class. Top marks for including the example file, makes it all that much easier too.

For what it's worth, I have tweaked the class a little, so as to allow a css-based paging (<li>) menu, with the choice of menu style included in the class call. So the call is now

function createPaging($query,$resultPerPage,$liststyle)

where $liststyle will be something like "navlist"

and then the display paging function is:

function displayPaging()
{
if($this->totalresult > 0){ // display results

echo '<div id="'.$this->liststyle.'"><ul>';

$self = $_SERVER['PHP_SELF'];
if($this->openPage<=0) {
$next = 2;
}

else {
$next = $this->openPage+1;
}
$prev = $this->openPage-1;
$last = $this->pages;

if($this->openPage > 1) {
echo "<li><a href=$self?page=1>First</a></li>";
echo "<li><a href=$self?page=$prev>Prev</a></li>";
}
//else {
// echo "<li>First</li>";
// echo "<li>Prev</li>";
// }
for($i=1;$i<=$this->pages;$i++) {
if($i == $this->openPage)
echo "<li>$i</li>";
else
echo "<li><a href=$self?page=$i>$i</a></li>";
}
if($this->openPage < $this->pages) {
echo "<li><a href=$self?page=$next>Next</a></li>";
echo "<li><a href=$self?page=$last>Last</a></li>";
}
else {
echo "<li>Next</li>";
echo "<li>Last</li>";
}

echo '</ul></div>';
}
}
}

(I also added a totalresult=0 trap)

Anyway, thanks again, great code!