How do I retrieve category from db then show the number of i
Posted: Fri Mar 10, 2006 6:39 am
Hi all,
I'm trying to display a list of categories (successfully) and the number of items in them (unsuccessfully) with the following code:
I'm getting the category name with the total number of rows returned next to each instead of the number of items in them.
I'm not too hot with working with arrays at the moment and could really use some help!!
Thank you in advance,
Matt
I'm trying to display a list of categories (successfully) and the number of items in them (unsuccessfully) with the following code:
Code: Select all
$sql = "SELECT DISTINCT category FROM catalogue";
$result = mysql_query($sql); // Issue the query
$category = $sql -> category;
$sql = "SELECT prod_id FROM catalogue";
$result2 = mysql_query($sql);
$rows = mysql_fetch_array($result2);
foreach ($rows as $count){
$count=mysql_num_rows($result2);
}
echo "Please select a category<p><ul>";
while($output = mysql_fetch_array($result)){
echo "<li><a href=\"{$PHP_SELF}?pagename=shop&ecommerce=on&category=$output[category]\">".$output[category]."</a>".$count."</li><br>";
}
echo "</ul>";
mysql_close();I'm not too hot with working with arrays at the moment and could really use some help!!
Thank you in advance,
Matt