选择数据库中条目最多的类别
我已经到了可以显示每个类别中有多少条目的阶段。它回显这样的数据
There are 6 in the category number1
There are 4 in the category number2
There are 1 in the category number4
There are 1 in the category number5
There are 1 in the category number8
但是我想要的是它显示最流行的类别。例如 - 最流行的类别是“”和“”条目
代码:
- $count_query_v1 = "SELECT categoryNo, COUNT(entryNo)
FROM entries
GROUP by categoryNo;
";
$answer = mysql_query($count_query_v1) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($answer)){
echo "There are ". $row['COUNT(entryNo)'] ."in the category number". $row['categoryNo'] ." ;
}
我将如何解决这个问题?
i have got to the stage where i can display a count of how many entries are in each category. It echo's the data like this
There are 6 in the category number1
There are 4 in the category number2
There are 1 in the category number4
There are 1 in the category number5
There are 1 in the category number8
However all i want is it to show the most popular category. So for instance - the most popular categoryNo is "" with "" entries
Code:
- $count_query_v1 = "SELECT categoryNo, COUNT(entryNo)
FROM entries
GROUP by categoryNo;
";
$answer = mysql_query($count_query_v1) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($answer)){
echo "There are ". $row['COUNT(entryNo)'] ."in the category number". $row['categoryNo'] ." ;
}
How would i go about this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
定义“最受欢迎”。如果您的意思是最受欢迎的类别是包含最多条目的单个类别,那么这将是您的查询:
Define "the most popular". If you mean the most popular category is a single category containing the most entries, then this would be your query: