jacko_162 Posted November 6, 2007 Share Posted November 6, 2007 i have a table with products, each product i add has its own catagory, if i list the catagories like so; <? // Query to pull information from the "products" Database $ret = mysql_query("SELECT * FROM $table1"); { // Query to pull information from the "catagory" Database $result = mysql_query("select * from $table13 order by view DESC"); while ($row = mysql_fetch_object($result)) { ?> <img src="images/arrow.gif"> <a href="products.php?catagory=<? echo $row->name; ?>"> <? echo $row->name; ?></a> (<? echo mysql_num_rows($ret); mysql_free_result($ret);?>)<br> <? }} ?> i want it to count the amount of products in each catagory; for example; Catagories; > Fish (3) > Corals (2) > Inverts (1) Still a newbie at this. Link to comment https://forums.phpfreaks.com/topic/76260-problems-with-count/ Share on other sites More sharing options...
revraz Posted November 6, 2007 Share Posted November 6, 2007 What is the { for here? $ret = mysql_query("SELECT * FROM $table1"); { Link to comment https://forums.phpfreaks.com/topic/76260-problems-with-count/#findComment-385992 Share on other sites More sharing options...
cooldude832 Posted November 6, 2007 Share Posted November 6, 2007 try a count(fieldname) type of query it will be better for you tizag has a nice tutorial on it Link to comment https://forums.phpfreaks.com/topic/76260-problems-with-count/#findComment-385994 Share on other sites More sharing options...
jacko_162 Posted November 7, 2007 Author Share Posted November 7, 2007 i tried the count thing from tizag but cant get it to work. ??? Link to comment https://forums.phpfreaks.com/topic/76260-problems-with-count/#findComment-386973 Share on other sites More sharing options...
GingerRobot Posted November 7, 2007 Share Posted November 7, 2007 Your code doesn't really make much sense to me. You are looping through results from whatever table is in $table13 to produce your links. Yet the number you echo is supposed to be the number of rows returned from another table($table1), so you would always end up with the same number on each category. What is your table structure? Where are you trying to get the information from? Link to comment https://forums.phpfreaks.com/topic/76260-problems-with-count/#findComment-387055 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.