John Davidson

php - how to select product according to the category

0 comments
Message:


This is my code in categories


    $query = "SELECT * FROM categories ORDER BY cat_id ASC";
$result = mysqli_query($query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
?>
<li><a href="product.php?id=<?php echo $row["cat_id"]; ?>"><?php echo $row["categoriesname"]; ?></a><li>



and This is my code in product.php


    $query = "SELECT * FROM product ORDER BY id";
$result = mysqli_query($query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
?>

<div class="col-md-4" style="margin-top:10px;">
<form method="post" action="orders.php?action=add&id=<?php echo $row["id"]; ?>">
<br>
<div style="border:5px solid #5cb85c; background-color:whitesmoke; border-radius:10px; padding:20px; height:420px" align="center">
<h4 class="text-success"><?php echo $row["product_category"]; ?></h4>

<img src="admin/public/img/<?php echo $row["images"]; ?>" class="img-responsive" width="200" height="300"/>

<h4 class="text-info"><?php echo $row["product_name"]; ?></h4>

<h4 class="text-danger">₱ <?php echo $row["product_price"]; ?></h4>

<input type="number" name="quantity" value="1" class="form-control" />

<input type="hidden" name="hidden_name" value="<?php echo $row["product_name"]; ?>" />

<input type="hidden" name="hidden_image" value="<?php echo $row["images"]; ?>" />

<input type="hidden" name="hidden_price" value="<?php echo $row["product_price"]; ?>" />
<br>

<input type="submit" name="add_to_cart" style="margin-top:5px;" class="btn btn-success" value="Add to Cart" />

</div>
</form>
</div>



how to do that? how to select according to the category? this is shopping cart...I want to show all of the product by selecting the category..



My Answer:
"SELECT * FROM products WHERE category_id = :category_id";
$stmt = $pdo->prepare($query);
$stmt->bindParam(':category_id', $category_id);
$stmt->execute();
$products = $stmt->fetchAll();

Rate this post

5 of 5 based on 9828 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us