I've been trying to make dynamic queries, where the user determines what will be queried. The reason is because I'd like the images being displayed in my gallery reflect the category selected by the user.
mysql_query("SELECT(whatever category they chose) FROM products")
below is the generation of categories as links. (not sure if it is set up for the task)
<?
include "storescripts/connect_to_mysql.php";
$data = mysql_query("SELECT category FROM products") or die(mysql_error());
$info = mysql_fetch_array( $data );
while($info = mysql_fetch_array( $data ))
{
$category = $info["category"];
print '<li><a href="'. $category .'"> ' . $category . ' </a> </li>';
}
?>
I'm really lost on how to get the images to reflect which category they chose. As of right now, the images are loading with this code.
<?php
include "storescripts/connect_to_mysql.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 10");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$subcategory = $row["subcategory"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .=
'
<div>
<li>
<a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="180" height="255" border="1" /></a>
<h4> <a href="product.php?id= ' . $id . '"> ' . $product_name . ' </a> </h4>
<p>'. $subcategory .'</p>
<span> $' . $price . '</span>
</li>
</div>
';
}
} else {
$dynamicList = "There are no products listed at this time.";
}
mysql_close();
?>
Any help would be greatly appreciated.
Thank you.