Hi, I don't know if this is possible or a really stupid question. I was wondering if after a select query has been executed can the results be filtered for specific values, and not just a single value but 7 different values. with what i want to accomplish its either im making it difficult for myself or the solution is pretty simple.
okay for example i have a select query like so:
$stmt = $conn->prepare("SELECT id, name, price, type, img FROM table");
$stmt->execute();
$result = $stmt->fetchAll();
now i have a page that has buttons which represent different types of "type". each button when clicked displayes images that corresponds to the type, i am using bootstrap for this. example pic:
so its like if bowls and feeders is clicked then the corresponding images will appear which were selected from database, and same goes to the rest of the buttons. right now i have succeeded in displaying the images but because there isnt a "filter" function or "where" clause in the query all the images are displayed regardless of the "type"
page.php:
$stmt = $conn->prepare("id, name, price, type, img FROM table ");
$stmt->execute();
$result = $stmt->fetchAll();
<div class="container">
<div class="row">
<div class="gallery col-lg-12 col-md-12 col-sm-12 col-xs-12">
<h1 class="gallery-title">Products</h1>
<div class="button-create">
<button class="btn btn-default" type="button" name="create"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add new product</button>
</div>
</div>
<div align="center">
<button class="btn btn-default filter-button" data-filter="all">All</button>
<button class="btn btn-default filter-button" data-filter="bf">Bowls and Feeders</button>
<button class="btn btn-default filter-button" data-filter="fur">Beds and Furnitures</button>
<button class="btn btn-default filter-button" data-filter="cats">Adopt a Cat</button>
<button class="btn btn-default filter-button" data-filter="food">Cat Food</button>
<button class="btn btn-default filter-button" data-filter="groom">Grooming Supplies</button>
<button class="btn btn-default filter-button" data-filter="litter">Litter Boxes</button>
<button class="btn btn-default filter-button" data-filter="toys">Toys</button>
</div>
<br/>
<?php
foreach($result as $row ) {
if ($row['img'] == "" ) { ?>
<div class="gallery_product col-lg-4 col-md-4 col-sm-4 col-xs-6 filter bf">
<img src="products/noimage.png" class="img-responsive">
<?php }
else { ?>
</div>
<div class="gallery_product col-lg-4 col-md-4 col-sm-4 col-xs-6 filter bf">
<a href="products_details.php?pid=<?php echo $row['id']; ?>" class="btn btn-warning btn-xs" role="button"><img src="products/<?php echo $row['img'] ?>" alt="<?php echo $row['name'] ?>" class="img-responsive"></a>
<p class="product-name"><?php echo $row['name'] ?></p>
<p class="product-price">RM <?php echo $row['price'] ?></p>
<?php }
}?>
</div>
//I DID THIS SECOND ONE THINKING IT WILL DIFFERENTIATE TYPES
<?php
foreach($result as $row ) {
if ($row['img'] == "" ) { ?>
<div class="gallery_product col-lg-4 col-md-4 col-sm-4 col-xs-6 filter fur">
<img src="products/noimage.png" class="img-responsive">
<?php }
else { ?>
</div>
<div class="gallery_product col-lg-4 col-md-4 col-sm-4 col-xs-6 filter fur">
<a href="products_details.php?pid=<?php echo $row['id']; ?>" class="btn btn-warning btn-xs" role="button"><img src="products/<?php echo $row['img'] ?>" alt="<?php echo $row['name'] ?>" class="img-responsive"></a>
<p class="product-name"><?php echo $row['name'] ?></p>
<p class="product-price">RM <?php echo $row['price'] ?></p>
<?php }
}?>
</div>
I hope i am explaining myself properly as im sleep deprived, please let me know if my explaination isn't clear. I also hope that wtv i am doing actually makes sense because i do need the "category menu" which shows thumbnail of products respectively. or if someone has a better idea of doing that, that would be great.
thanks in advance.