Reputation: 7
Hello everybody i have a ecommerce website with 20 products on but i am looking to expand my product list to 100 different products.
now instead of having 100 seperate pages for 100 different products i would like to use the $_GET variable to display all products on the same page depending on the product id.
i just don't know where to go from here as in pulling the information from the database and displaying it.
---PRODUCT.PHP---
<?php include 'includes/header.php';
if(isset($_GET['pid']) && empty($_GET['pid']) === false) {
$productid = htmlentities($_GET['pid']);
echo intval($_GET['pid']);
}else{
header('Location: home.php');
die();
}
?>
here is also my directory structure if it helps.
p_id, P_name, p_description, p_category, p_price, thanks in advance.
Upvotes: 0
Views: 1394
Reputation: 3276
I would update the SQL query if I were you - so for example:
if(isset($_GET['pid']) {
$pid = $_GET['pid]';
$SQL = "SELECT stuff FROM Products WHERE id = " . $pid;
} else {
$pid = '';
}
This would only get the records for that specific product id that the user have selected by adding the WHERE clause with the value of $_GET['pid']
Upvotes: 2