nitemare with count

im in a nightmare here with count. i have 2 categorys. cat with id 1 and cat with id 2,

now everything display right except for the row count cat with id 1 has 2 topics and cat with id 2 has 1 topic but it displays record count of 3 on both cats

[php]$sql = “SELECT * FROM forums, forum_categories WHERE forum_categories.cat_id = forums.cat_id ORDER BY forums.forum_id DESC”;
$result = query($sql);
$topics_count = row_count($result);

$displayedCategories = array();

while (($row = mysqli_fetch_assoc($result)) != false) {

if (!in_array($row['cat_id'], $displayedCategories)) {        
  

    $cat_id = $row['cat_id'];        
    $cat_title = $row['cat_title'];
    
    $displayedCategories[] = $row['cat_id'];

    $forum_name = $row['forum_name'];        
    $forum_last_post_id  = $row['forum_last_post_id']; 
    
   
echo "<tr>";
echo "<td>$cat_id</td>";
echo "<td><a href='viewforum.php?f={$cat_id}'>$cat_title</a><br>$forum_name Admin</td>";
echo "<td>$topics_count</td>";
echo "<td>0</td>"; 

echo "</tr>";
}

} [/php]

$topics_count is giving you the total number of returned results. If you want them itemized, you will want to add a count(*) into your SQL query.

I have still same result i have tried count group id = id same result for all

I don’t think you are understanding what I am saying.

You can do this one of two ways. Adding a counter variable to count the number of id’s that are the same, OR and preferable, count the number of id’s in the database and return that value for printing.

[php]SELECT COUNT(*) as total FROM forums WHERE forums.cat_id = 1[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service