Trying to get a code to display the categories of my posts and Im having an issue with presenting the number of posts per category.
well, you get my point while looking in the code, now the total number of categories is listed on every category…
here we go:
<?php
$listresult = mysql_query("SELECT distinct category FROM test_blog")
or die(mysql_error());
$totalpostspercategory = mysql_num_rows($listresult);
echo "<ul>";
while($row = mysql_fetch_array( $listresult )) {
if (strlen($row['category']) > 45) {
$row['category'] = substr($row['category'],0,45) . " ...";
}
echo "<li><a href='index.php?category=" . $row['id'] . "'>" . $row['category'] ."</a> (" . $totalpostspercategory . ")</li>";
}
echo "</ul>";
?>
Assuming your table looks something like this . . .
You can get the count directly using SQL by