PHP MySQL Query在过去24小时内最受欢迎 [英] PHP MySQL Query most popular in last 24 hours

查看:157
本文介绍了PHP MySQL Query在过去24小时内最受欢迎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我想在过去24小时内获得MOST喜欢的10条记录。这是我迄今为止所做的:

  $ date = date(o-m-d); 
$ query =SELECT date_created,COUNT(to),from,to FROM like WHERE date_created LIKE'$ date%'GROUP BY to ORDER BY COUNT(to)DESC LIMIT 10;

的问题是它只能从THAT天,不管今天有多远。最近24小时内没有最受欢迎的消息。



喜欢的结构:到| date_created | id



日期标准ISO时间 - 例如2010-07-14T00:35:31-04:00。直接从PHP引用:date(c);

解决方案

  WHERE date_created > DATE_SUB(NOW(),INTERVAL 24 HOUR)


Say I want to get ten records with the MOST likes in the last 24 hours. Here's what I have so far:

$date = date("o-m-d");
$query = "SELECT date_created,COUNT(to),from,to FROM likes WHERE date_created LIKE '$date%' GROUP BY to ORDER BY COUNT(to) DESC LIMIT 10";

The problem with that is that it only gets the most liked from THAT DAY, no matter how far into that day it is. It doesn't get the most liked from the last 24 hours.

structure for likes: from | to | date_created | id

dates are in standard ISO time - example 2010-07-14T00:35:31-04:00. Come straight from the PHP reference: date("c");

解决方案

WHERE date_created > DATE_SUB( NOW(), INTERVAL 24 HOUR)

这篇关于PHP MySQL Query在过去24小时内最受欢迎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆