0

I'm trying to get count of posts in "posts" table,

i have id,topic_id (topic_id= the topic id)

in "topics" table,

i have id,f_id (f_id= the forum id )

i try while and while, but not wor how can i count the posts? for ex:

<php?
$test2=mysql_query("SELECT *, COUNT(topic_id) AS post_count FROM posts t LEFT JOIN topics p ON p.id = t.id WHERE `f_id`='1' GROUP BY t.id") or die (mysql_error());
?>

1 Answers1

0

Try this query :

SELECT *, COUNT(topic_id) AS post_count 
FROM posts t 
LEFT JOIN topics p 
ON p.id = t.id AND `f_id`='1' 
GROUP BY t.id
A.Essam
  • 1,094
  • 8
  • 15