I have a dynamic page that pulls the categories from the database. this page is categories.php?CTGID=####, CTGID standing for the category number. Each product then has an ID assigned to it.
When they click on the product within the category it goes to a page Products.php?ID=###. What I want to create is when they are within the Product page there is a next and previous button.
What I would essentially need it to do is get the CTGID of the current product ID then the next button would be the ID of the next product withing that Category ID.
<?php
$db=mysql_connect ("localhost",[username],[password]) or die(mysql_error());
mysql_select_db("rentals");
$rentID = $_GET['ID'];
//Strip html
$strip_ID = strip_tags($rentID);
$html = htmlentities($strip_ID, ENT_QUOTES);
$escape = addslashes($html);
$table="online_rental_db";
$sql = "SELECT * FROM $table WHERE ID=$escape";
$query = mysql_query($sql) or die(mysql_error());
$rentals = mysql_fetch_assoc($query);
$description = ucwords(strtolower($rentals['Description']));
$image = $rentals['Image'];
$download = $rentals['PDF'];
$ID = $rentals['ID'];
$CTGID = $rentals['CTGID'];
$category = $rentals['Category'];
$video = $rentals['Video'];
$bytes = filesize("rentals/".$download);
$model = $rentals['Model'];
$made = ucwords(strtolower($rentals['Manufacturer']));
$productnum = $rentals['Productnum'];
then on the page I just echo out what I need in what area. I have read some articles on the next and previous buttons, but decided I might need some extra advice!
Not sure what you’ve tried, but in the past I’ve implemented getting next/previous values from the DB with the following queries:
If you get no result back from one of the two queries, it means you are on the first or last item in that category so there is no prev/next button in that case.
Hope that helps.