如何通过热门/上升的帖子订购
I have DB of posts with:
我有以下数据库:
post_id(int(7)) user_id(int(7)) post_txt(text) post_time(varchar(30)) likes_count(int(10))
(the post_time is look like this "5-4-2016 17:41")
(post_time看起来像这样“5-4-2016 17:41”)
I want to order it by "hot posts" e.g. "likes_count/post_time".
我想通过“热帖”订购,例如“likes_count / post_time”。
How can I do it?
我该怎么做?
This is how I do it now:
这就是我现在的做法:
$que_post=mysql_query("select * from user_post order by post_id desc");
PS. I know that this is not how you save likes usually, but I do it for purpose
PS。我知道这不是你通常喜欢的方式,但我是出于此目的
Edit-Example data:
97||25||Hello world||8-4-2016 14:19||19
The algorithm I want to use is time/likes. I know its bad algorithm, but I just want to understand the basics. I would like to know if you know good algorithm for that
我想要使用的算法是时间/喜欢。我知道它的算法不好,但我只想了解基础知识。我想知道你是否知道好的算法
2 个解决方案
#1
1
You should change type of post_time
field to DATETIME
(read manual). All your lines have to be converted by some script to format YYYY-MM-DD HH:MM:SS
. When you do it, everything will work.
您应该将post_time字段的类型更改为DATETIME(阅读手册)。所有行都必须通过某些脚本转换为YYYY-MM-DD HH:MM:SS格式。当你这样做时,一切都会奏效。
Your problem appears cause of sorting by alphabet as text. For example: 01.01.2016 as text is less than 31.01.1999.
您的问题出现的原因是按字母顺序排序为文本。例如:01.01.2016,因为文本小于31.01.1999。
更多相关文章
- php大转盘抽奖算法
- PHP的文本到HTML转换器
- PHP用空格分割文本为数组的方法
- php 写一个算法,查寻数组里第一个大于某数的值。
- thinkPHP5下扩展encryptedData解密算法文件的注意事项
- 仅在我的文本框中验证数字和字母
- php,检查文本拆分的正确性
- 如何使用Ajax或Jquery填充文本框中的值?
- 当excel表格单元格的格式是日期格式非文本格式的时候,phpexcel 应