Hello all,
I have a search page, it does a very basic search, but the pagination doesn't work properly.
If I am on Page 2, it shows Page 1 as the current page and not as a link, and page 2 shows as a link when im already at page two.
I would apreciate any help.
Here is the relevant code:
$get_data = mysql_query("SELECT keywords.*, Product.* FROM keywords, Product WHERE keywords.keyword='$phrase' AND keywords.sku = Product.SKU") or die(mysql_error());
$sku_use=0;
$count=0;
while ($row=mysql_fetch_array($get_data))
{
if ($row[sku] != $sku_use)
{$count++; }
}
$count is to count how many results, of course.
//Pagination step 1 Begins
$limit = 10;
$totalrows = $count;
if(empty($page)){
$page = 1;
}
$limitvalue = $page * $limit - ($limit);
//Pagination step 1 Ends
$get_entries = mysql_query("SELECT keywords.*, Product.*, Price_Range.* FROM keywords, Product, Price_Range WHERE keywords.keyword='$phrase' AND keywords.sku = Product.SKU AND Product.Price_Range_ID = Price_Range.Price_Range_ID ORDER BY Price_Range.rangeID ASC LIMIT $limitvalue, $limit") or die(mysql_error());
//Pagination step 2 Begins
if($page != 1){
$pageprev = $page--;
echo("<a href=\"./key.php?page=$pageprev&phrase=$phrase\">PREV ".$limit."</a>  ");
}else{
echo("PREV".$limit." ");
}
$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"$PHP_SELF?page=$i&phrase=$phrase\">$i</a> ");
}
}
if(($totalrows % $limit) != 0){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"$PHP_SELF?page=$i&phrase=$phrase\">$i</a> ");
}
}
if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page++;
echo("<a href=\"$PHP_SELF?page=$pagenext&phrase=$phrase\">NEXT ".$limit."</a>");
}else{
echo("NEXT".$limit);
}
//Pagination step 2 Ends
Would anyone know what is going on? Why is the wrong page being displayed as the correct page?
Thx
MK