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。

更多相关文章

  1. php大转盘抽奖算法
  2. PHP的文本到HTML转换器
  3. PHP用空格分割文本为数组的方法
  4. php 写一个算法,查寻数组里第一个大于某数的值。
  5. thinkPHP5下扩展encryptedData解密算法文件的注意事项
  6. 仅在我的文本框中验证数字和字母
  7. php,检查文本拆分的正确性
  8. 如何使用Ajax或Jquery填充文本框中的值?
  9. 当excel表格单元格的格式是日期格式非文本格式的时候,phpexcel 应

随机推荐

  1. Android神器:Xposed框架
  2. 基于android的远程视频监控系统
  3. Android 5.0特征补充4-DrawerLayout
  4. Android 可拖动的进度条:SeekBar之简单使
  5. 菜鸟窝-仿京东淘宝项目学习笔记(二)ToolBar
  6. MediaPlayer源码存在的内存泄漏问题,释放
  7. Android进程间(IPC机制)通信(Bundler,Messe
  8. 从零开始的Android新项目10 - React Nati
  9. Android自定义控件---打造不一样的FlowLa
  10. Android中bindService的细节之二:从进程的