Pagination in category

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • slsv
    New Member
    • Apr 2013
    • 14

    Pagination in category

    Hello,
    I have a page whit categories. The problem that I'm facing is how to make pagination in the category? When I click for exaple 'Autos' and open images only from 'Autos' how to change next image from this category?

    I have this so far but when I load category the page is blank.
    Code:
    $cat_id = $_GET['cat_id'];
                $cat_id = mysqli_real_escape_string($con, $cat_id);
                $query = "SELECT * FROM images JOIN cats ON images.img_category = cats.cat_id WHERE cats.cat_id = '$cat_id'";
                $result = mysqli_query($con, $query) or die("Query failed: " . mysqli_errno($con));
                if (isset ($_GET['id'])) {
                    $id = $_GET['id'];
                $prevSQL = mysqli_query($con,"SELECT id FROM images WHERE id < $id ORDER BY id DESC LIMIT 1") or die (mysqli_error($con));
                $nextSQL = mysqli_query($con, "SELECT id FROM images WHERE id > $id ORDER BY id ASC LIMIT 1") or die (mysqli_error($con));
                $prevobj=mysqli_fetch_object($prevSQL);
                $nextobj=mysqli_fetch_object($nextSQL);
                $pc = mysqli_fetch_object(mysqli_query($con, "SELECT COUNT(id) as pid FROM images WHERE id<$id ORDER BY id DESC")) or die (mysqli_error($con));
                $nc = mysqli_fetch_object(mysqli_query($con, "SELECT COUNT(id) as nid FROM images WHERE id>$id ORDER BY id ASC")) or die (mysqli_error($con));
                $prev=$pc->pid>0 ? '<a href="pic.php?cat_id='.$cat_id.'&id='.$prevobj->id.'">Prev</a> |' : '';
                $next=$nc->nid>0 ? '<a href="pic.php?cat_id='.$cat_id.'&id='.$nextobj->id.'">Next</a>' : '';
    
    
                $row = mysqli_fetch_array($result);
                echo "<div id=\"picture\">";
                echo "<img src=\"upload/" . $row['name']  . "\" alt=\"\" /><br />";
                echo $row['caption'] . "<br />";
                echo "</p>";
                echo $prev;
                echo $next;
    
    echo '</div>';
                }
Working...