Hey Everyone,
So I have cleaned up my code a bit, but now I'm running into a whole new mess of issues.
Well, just one really.
When I click the category links to sort the while loop echo based on the category in the database it works fine.
But when I click on "next page" it just goes to the 2nd page of all the products, not just the ones in the category.
Let me explain it a different way. When I open the page, it shows all items in the database, with all the pageination working properly, when I click the link to sort them by category, that works as well, but when I click the next button while in the category to go to the next page, it goes to the second page of all items.
Once again sorry about the messy code, I feel like I'm missing a conditional statement for when I click the category, but I don't know how to approach it.
If you want to see the full code...http://pastebin.com/embed.php?i=0cFf6QkH
<?php
require_once("includes/connect.php");
if(isset($_GET['category'])) {
$cat = mysql_real_escape_string($_GET['category']);
$base_query = "SELECT guns_id,guns_brand,guns_model,guns_img,guns_price FROM tbl_guns WHERE guns_cat = '".$cat."' ORDER BY guns_id DESC";
}else{
$base_query = "SELECT guns_id,guns_brand,guns_model,guns_img,guns_price FROM tbl_guns ORDER BY guns_id DESC";
}
$result = mysql_query($base_query);
$total = mysql_num_rows($result);
$rowsperpage = 3;
if(isset($_GET['page'])) {
$pagenum = $_GET['page'];
}else{
$pagenum=1;
}
$offset = ($pagenum - 1) * $rowsperpage;
$maxpage = ceil($total/$rowsperpage);
$self = $_SERVER['PHP_SELF'];
$query = "$base_query LIMIT $offset,$rowsperpage";
$result = mysql_query($query);
if ($pagenum > 1) {
$page = $pagenum - 1;
$prev = "<a href=\"".$self."?page=".$page."\">prev</a>";
$first = " <a href=\"".$self."?page=1\">first</a> ";
}else{
$prev = " ";
$first = " ";
}
if ($pagenum < $maxpage) {
$page = $pagenum + 1;
$next = "<a href=\"".$self."?page=".$page."\">next</a>";
$last = " <a href=\"".$self."?page=".$maxpage."\">last</a>";
}else{
$next = " ";
$last = " ";
}
?>
</div>
<div id="productsInfo">
<?php
while($row = mysql_fetch_array($result)) {
echo "<div class=\"productIcon\">
<a href=\"productdetails.php?id=".$row['guns_id']."\">
<img class=\"thumbReSize\" src=\"images/".$row['guns_img']."\" />
".$row['guns_brand'].
"<br />".$row['guns_model'].
"<br />$".$row['guns_price'].
"</a>
</div>";
}
?>
<div id="paginationContainer"><?php
echo $first." ".$prev." Page ".$pagenum." of ".$maxpage." pages ".$next." ".$last;
?>
</div>