gpt4 book ai didi

PHP 统计论坛帖子数

转载 作者:行者123 更新时间:2023-11-30 00:26:41 25 4
gpt4 key购买 nike

我正在尝试获取帖子数在“帖子”表中,

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

在“主题”表中,

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

我时不时地尝试,但不行我如何计算帖子数?例如:

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

最佳答案

尝试这个查询:

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

关于PHP 统计论坛帖子数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22821841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com