简体   繁体   English

PHP计数论坛帖子

[英]PHP count forum posts

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());
?>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM