Hello, I'm sure I'm missing something small. If a category doesn't exist in the database yet, how can I have the query accept a value of 0 without reporting an error? The $subcategory is what the user selected. The result should either be 4 images or a blank place holder with an echo (couldn't figure out the echo either, just got more errors.)
Here is my error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /product.php on line 38
Thank you for your help.
<?php
include "storescripts/connect_to_mysql.php";
$tinysubcategory = "";
$tinysql = mysql_query("SELECT * FROM products WHERE subcategory ='". $subcategory ."' LIMIT 4");
$tinyproductCount = mysql_num_rows($tinysql); // count the output amount
if ($tinyproductCount > 0) {
while($row = mysql_fetch_array($tinysql)){
$id = $row["id"];
$product_name = $row["product_name"];
$details = $row["details"];
$subcategory = $row["subcategory"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$tinysubcategory .=
'
<th valign="top">
<a href="product.php?id=' . $id . '">
<img style="border:#FFF 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="70" height="70" border="2px" />
</a>
<h3> <a href="product.php?id= ' . $id . '"> ' . $product_name . ' </a> </h3>
</th>';
}
} else {
$tinysubcategory .=
'<img style="border:#FFF 1px solid;" src="inventory_images/productholder.png" alt="Nothing to display!" width="70" height="70"" />
<br/>';
}
mysql_close(); ?>
<? echo $tinysubcategory; ?>