我有一张桌子categories
:id, name, subcategory_id, parent_id
. 另一个表classifieds
有:classified_id, title, description, category_id
。
我正在尝试提取每个类别中的分类广告数量。所以它看起来像这样。
- 配件(10)
- 汽车(15)
- 约会(12)
我试了一下:
enter $catquery = mysql_query("SELECT * FROM categories WHERE sub_id = '0' ORDER BY name ASC"); here
enter $catrows = mysql_num_rows($catquery); here
enter $catrows = mysql_num_rows($catquery); here
enter $query = "SELECT category_id, COUNT(title) AS `total` FROM classifieds WHERE classified_id = 'category_id' "; here
enter $result = mysql_query($query); here
enter while($row = mysql_fetch_assoc($result)){ $num_items_in_category[$row['category_id']] = $row['total']; here
enter } echo "<li><a href='category.php?cat=".$row['id']."'>".$row['name']. $row['total']. "</a></li>"; here
谢谢各位