Hello all
I'm having abit of a problem with this pagination script, the first page displays ok but as soon as you click on the second page it loses the query and you end up with a blank page, here is the script.
PHP Code:
<?php
include "db.php";
$category = $_POST['category'];
function per_page($link, $offset) {
global $numofpages, $page;
$numofpages = round($numofpages);
$pagesstart = round($page-$offset);
$pagesend = round($page+$offset);
if ($page != "1" && round($numofpages) != "0") {
echo str_replace("%page", round($page-1), '<a href="'.$link.'"><<</a> ');
}
for($i = 1; $i <= $numofpages; $i++) {
if ($pagesstart <= $i && $pagesend >= $i) {
if ($i == $page) {
echo "<b>[$i]</b> ";
}
else {
echo str_replace("%page", "$i", '<a href="'.$link.'">'.$i.'</a> ');
}
}
}
if (round($numofpages) == "0") {
echo "[$i]";
}
if ($page != round($numofpages) && round($numofpages) != "0") {
echo str_replace("%page", round($page+1), '<a href="'.$link.'">>></a>');
}
}
/* Set How many results to display per page */
$pp = "4";
/* Select the table that you want to view, you can add things like WHERE something='something' */
$table = "hw73ksu349x_hjsd63";
$total = mysql_result(mysql_query("SELECT COUNT(title) FROM $table WHERE category='$_POST[category]' ORDER BY pr DESC"),0);
$numofpages = $total / $pp;
if (!isset($_GET['page'])) {
$page = 1;
}
else {
$page = $_GET['page'];
}
$limitvalue = $page * $pp - ($pp);
/* Display the rows */
$query = "SELECT * FROM $table WHERE category='$_POST[category]' ORDER BY pr DESC LIMIT $limitvalue, $pp";
$result = mysql_query($query);
while($r=mysql_fetch_array($result))
{
if ($e == "0"){ $color="#C1F2FF"; $e=1; }else{
$color="#93EAFF"; $e=0; }
echo "<table width='100%' border='0' cellspacing='1' cellpadding='0'>
<tr>
<td width='77%'><span class='style20'><a href='".$r['link']."'>".$r['title']."</a> </span></td>
<td width='23%'><a href='mailto:".$r['email']."'>Email</a></td>
</tr>
</table><hr>";
}
/* Display the pages down the bottom */
echo '<center><br>Pages: '.round($numofpages).'<br>';
per_page("?page=%page", "4");
?>
I would be very greatful if you could help me and would be willing to make a small donation to somebody via paypal. Pm me here or post a reply. Thank you
Last edited by techwench; 06-26-2006 at 11:38 AM..
Reason: code highlight php
|