'How to display product details when the image is clicked in PHP and MYSQL
I've made a website that displays all products with images. Now what I'm trying to figure out is, how to make the image clickable and when the image is clicked it displays the product information page? Thank you for your help! :)
This is my product.php page.
<?php
include_once 'includes/dbh.inc.php';
?>
<body>
<!--- featured products --->
<div class="small-container">
<div class="row row-2">
<h2 class="title"> Featured Products</h2>
<select>
<option>Default</option>
<option>By Price</option>
</select>
</div>
<div class="row">
<?php
$sql = "SELECT * FROM cakes;";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0 ) {
while ($row = mysqli_fetch_assoc($result)) {
?>
<div class="col-4">
<a href="product details.php"><img src= <?php echo $row['image'];?>></a>
<h4><?php echo $row['name']; ?></h4>
<p>$<?php echo $row['price']; ?></p>
</div>
<?php
}
}
?>
</div>
</div>
</body>
Below is my database.
Solution 1:[1]
Edit this:
<div class="col-4">
<a href="product details.php"><img src= <?php echo $row['image'];?>></a>
<h4><?php echo $row['name']; ?></h4>
<p>$<?php echo $row['price']; ?></p>
</div>
to this:
<div class="col-4">
<a href="product details.php?id_cakes=<?=$row['id']?>""><img src= <?php echo $row['image'];?>></a>
<h4><?php echo $row['name']; ?></h4>
<p>$<?php echo $row['price']; ?></p>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | beibei |

