Saturday, 31 August 2013

Why isn't my pagination code working?

Why isn't my pagination code working?

I have this pagination code and the &pagenum=whatever is showing up
perfectly fine in my URL but it just does absolutely nothing and I really
don't know why. Here is my code:
paginate.php:
<?php
include("config.php");
if (!(isset($pagenum)))
{
$pagenum = 1;
}
$data = mysql_query("SELECT * FROM shop
WHERE MATCH (name,description,keywords) AGAINST ('$search' IN BOOLEAN
MODE)") or die(mysql_error());
$rows = mysql_num_rows($data);
$page_rows = 5;
$last = ceil($rows/$page_rows);
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
?>
search.php:
<?php
include("config.php");
$search = mysql_real_escape_string($_GET['result']);
?>
<HTML>
<HEAD>
</HEAD>
<BODY>
<div id="wrapper">
<div class="searchleft">
</div>
<div class="search">
<center>
<form method="get" action="search.php">
<input type="text" name="result" value="<?php echo $search; ?>" />
<input type="submit" />
</form>
<?php
include("paginate.php");
$data_p = mysql_query("SELECT * FROM shop
WHERE MATCH (name,description,keywords) AGAINST ('$search' IN BOOLEAN
MODE) $max") or die(mysql_error());
$num_rows = mysql_num_rows($data_p);
if ($num_rows == "1") {
echo "Returned 1 result.";
} else { echo "Returned ".$num_rows." results."; }
while ($info = mysql_fetch_assoc($data_p)) {
$name = stripslashes($info['name']);
$desc = stripslashes($info['description']);
$desc = substr($desc, 0, 150);
$price = stripslashes($info['price']);
Print "<div style=\"width:600px; height:150px; border:1px solid black;
overflow:hidden\"><div style=\"height:148px; width:25%; border:1px
solid red; float:left\"><center><img src=\"".$picture."\"
height=\"120\" width=\"120\" style=\"margin-top:15px\"
/></center></div><div style=\"height:150px; width:50%; border:1px
solid blue; float:left; text-overflow: ellipsis;
padding-top:5px\"><center><font size=\"+1\"><b><a
href=\"result.php?product=".urlencode($name)."\">".$name."</b></a></font><br><br>".$desc."...</center></div><div
style=\"height:150px; width:24%; border:1px solid green;
float:left\"><center><h1>$".$price."</h1><button>Add to
Cart</button></center></div></div>";
}
echo " --Page $pagenum of $last-- <p>";
if ($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?result=".$search."&pagenum=1'>
First</a> ";
$previous = $pagenum-1;
echo " <a
href='{$_SERVER['PHP_SELF']}?result=".$search."&pagenum=$previous'>Previous</a>
";
}
if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " <a
href='{$_SERVER['PHP_SELF']}?result=".$search."&pagenum=$next'>Next</a>
";
echo " ";
echo " <a
href='{$_SERVER['PHP_SELF']}?result=".$search."&pagenum=$last'>Last</a>
";
}
?>
I'm honestly stumped.

No comments:

Post a Comment