I want to display a number of the mysql enteries basically page 1 1-10 page 2 2-20 when someone clicks next and previous it adds or subtracts 10 and when someone clicks last it multiplies the page number i really need help i been tearing my hair out for hoursCode:// This the full code which will generate a paging system $limit=10; // Limit of result per page ; $qresult = mysql_query("SELECT * FROM users"); // Let's get the query $nrResults=mysql_num_rows($qresult); // Count the results if (($nrResults%$limit)<>0) { $pmax=floor($nrResults/$limit)+1; // Divide to total result by the number of query you want // to display per page($limit) and create a Max page } else { $pmax=floor($nrResults/$limit); } $qresult = mysql_query("SELECT * FROM users LIMIT ".(($_GET["page"]-1)*$limit).", $limit"); //Need to generate query considering your limit while($row = mysql_fetch_array($qresult)) { // Now once we got the query from MySQL, we need to think what we to do it. You can do anything. This is just an example $add++; $first= $row['first']; $last= $row['last']; $votefor= $row['votefor']; $picture= $row['picture']; echo "<br/> <div> <table width=\"660\" border=\"0\"> <tr> <td ><span class=\"number\">$add</span></td> <td width=\"120\" rowspan=\"2\"><img src=\"http://www.shawnhbk.com/pres/images/$picture\" height=\"120\" /></td> <td><h2>$first $last</h2></td> </tr> <tr> <td width=\"88\" >Vote Up Vote Down</td> <td width=\"438\">$votefor </td> </tr> </table> </div> "; // Here comes the Real part of this Tutorial!! } echo "<div class='navpage'>"; // Make a simple css // We need to create a Previous page, so we need $pages to be bigger than 1, otherwise at the first page we would get a 0. //For the previous to show up we need at least to be at the second page. if($pages > 1) {$add=10; $prevp="<a href='index.php?add=$add&page=".($pages-1)."' title='Previous Page'>Previous Page</a>"; } else {echo "";} echo $prevp; // Here We want create a page from the results we got by dividing the total by the the limit. So let say you got //45 results and you want 5 results per page; these simple lines will create you 8 pages. $pid=1; while ($pid<=$pmax) { $paging= "<a href='index.php?page=$pid' title='Page $pid of $pmax'> $pid</a>"; //So here, let say we are at the 3rd page and we want the 3 to be blank so the user can know where is he now. //This will act as Current Page! We need to replace the url by a text $newpaging=str_replace("<a href='index.php?page=$pages' title='Page $pages of $pmax'> $pages</a>", "<span>$pages</span>", $paging); echo $newpaging; $pid++; // create pages until reach the result } //We want to create a next page and a last page, $pages have to be less than $pmax. if($pages < $pmax) { $nextp="<a href='index.php?page=".($pages+1)."' title='Next Page'>Next Page</a>"; } else {echo "";} echo $nextp; echo "<a href='index.php?page=$pmax' title='Last Page'>Last Page</a>"; echo "</div>"; ?>




Bookmarks