I am new to PHP, i am now stuck at the transferring of id selected into another page.
this is my first page, home.php
<?php
require 'dbfunction.php';
$con = getDbConnect();
if (mysqli_connect_errno($con)) {
"Failed to connect to MySQL: " . mysqli_connect_error();
} else {
$result = mysqli_query($con, "SELECT * FROM category");
while ($category = mysqli_fetch_array($result)) {
?>
<div class="col-md-4">
<a class="thumbnail" href="product.php?cat=<?php echo $category['categoryid']; ?>">
<img src="<?php echo "img/" . $category['image'] ?>" width="200" height="200">
<div class="title"><h3><?php echo $category['title']; ?></h3></div>
</a>
</div>
<?php
}
mysqli_close($con);
}
?>
My second page, product.php
<?php
require 'dbfunction.php';
$con = getDbConnect();
if (mysqli_connect_errno($con)) {
"Failed to connect to MySQL: " . mysqli_connect_error();
} else {
$result = mysqli_query($con, "SELECT * FROM product");
while ($product = mysqli_fetch_array($result)) {
?>
<div class="col-md-4">
<a class="thumbnail" href="productInfo.php?cat=<?php echo $product['categoryid']; ?>&code=<?php echo $product['productname']; ?>">
<img src="<?php echo "img/" . $product['productimage']; ?>" width="250" height="220">
<div class="title"><h3><?php echo $product['productname']; ?></h3></div>
</a>
</div>
<?php
}
}
?>
data in my database,
category
categoryid PM2103
name PaperModel
image papermodel.jpg
categoryid GP4567
name GlossyPaper
image GlossyPaper.jpg
product
categoryid PM2103
productname PaperModel
Productimage papermodel.jpg
categoryid PM2103
productname PaperModel222
Productimage papermodel222.jpg
categoryid PM2103
productname PaperModel333
Productimage papermodel333.jpg
categoryid GP4567
productname GlossyPaper
Productimage GlossyPaper.jpg
categoryid GP4567
productname GlossyPaper222
Productimage GlossyPaper222.jpg
when a person select a category in home.php, it would bring the person into another page product.php, with all the product in the category list. I'm not sure what code i should use to link them together.