我有一個表作爲blog_posts使用兩種表
+---------+-----------+
| postID | categoryID |
+========+============+
| 1 | 1 |
+--------+------------+
| 2 | 1 |
+--------+------------+
| 3 | 2 |
+--------+------------+
| 4 | 4 |
+--------+------------+
,另一個是blog_category
+---------+-----------+
| CategoryID | catName |
+========+============+
| 1 | cricket |
+--------+------------+
| 2 | sports |
+--------+------------+
| 3 | football |
+--------+------------+
| 4 | tennis |
+--------+------------+
現在我想顯示的類別和類別多少職位是有以及。喜歡的categoryID 1是在有1帖子ID和2的話,它會顯示板球,職位2.現在我只取了級別僅是簡單的:P
<ul>
<?php
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($conn,"SELECT * FROM blog_category ");
while($row = mysqli_fetch_array($result)) {
?>
<li>
<a class="f-categories-filter_name" href="blog-cat.php?id=<?php echo $row['categoryID'];?>"><i class="fa fa-plus"></i><?php echo $row['categoryName'];?></a>
<span class="b-categories-filter_count f-categories-filter_count">**I want to display here number of posts of that category**</span>
</li>
<?php } ?>
</ul>
工作正常,謝謝:* –