Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在计算结果之后对其排序_Php_Mysql_Count - Fatal编程技术网

Php 在计算结果之后对其排序

Php 在计算结果之后对其排序,php,mysql,count,Php,Mysql,Count,这段代码非常有效,但我不知道如何订购 示例输出: 点击3 Mozilla Firefox 点击2谷歌浏览器 点击4 Internet Explorer Hits 2苹果之旅 热门歌剧1 将SQL语句调整为 SELECT user_browser, COUNT(*) as hits FROM WEB_STATS WHERE real_user!='Bot' <-- replace the NOT LIKE 'Bot' GROUP BY user_browser ORDER BY

这段代码非常有效,但我不知道如何订购

示例输出:

点击3 Mozilla Firefox 点击2谷歌浏览器 点击4 Internet Explorer Hits 2苹果之旅 热门歌剧1

将SQL语句调整为

SELECT user_browser, COUNT(*) as hits
FROM WEB_STATS 
WHERE real_user!='Bot'      <-- replace the NOT LIKE 'Bot'
GROUP BY user_browser
ORDER BY hits DESC;

您只需查询一次,然后迭代结果

尝试排序如下:

子字符串\u INDEXcolName,2->点击2歌剧===>点击2 子字符串,INSTR'',colName->HITS 2==>2 强制转换为有符号->将2转换为数字 把它们放在一起

ORDER BY CAST(substring(substring_index(colName,2),INSTR(' ',colName)) AS SIGNED)

这应该可以满足您的要求……

您希望如何订购?输出示例是多列还是单个字符串?我希望点击按降序运行。上面的示例输出是它现在的显示方式。感谢真正的用户!='但是我没有要订购的点击数。如果我这样做了,我就不需要数数了。除非我遗漏了什么
ORDER BY CAST(substring(substring_index(colName,2),INSTR(' ',colName)) AS SIGNED)