php获得前一天日期中的24个小时,精确到分的查询问题。

[复制链接]
查看11 | 回复5 | 2011-4-18 05:30:17 | 显示全部楼层 |阅读模式
我数据表里的记录是 2010/1/2 12:00 2010/1/2 12:10 这样一个小时每10分钟记录了一次,我想在第二天获取每个小时的记录改如何写,在线等回答谢谢


for($i=1;$i24;$i)

{

$sql=\"select SUM(count) from all_online_info where time betwee\".\'date(\"Y/m/d\",strtotime(\"-1 day\")) i:00 and date(\"Y/m/d\",strtotime(\"-1 day\")) i:59;



}
这样写打印了一连串的字符。。。
回复

使用道具 举报

千问 | 2011-4-18 05:30:17 | 显示全部楼层
<pre id=\"best-answer-content\" class=\"reply-text mb10\">echo$sql=\'select SUM(count) from all_online_info where time betwee\'.date(\"Y/m/d\",strtotime(\"-1 day\")).\' \'.$i.

\':00 and \'.date(\"Y/m/d\",strtotime(\"-1 day\")).\' \'.$i .\':10br\';

















<h4 class=\"ask\">追问





<pre class=\"replyask-text\" id=\"content-4727252\">不好意思,我运行看了下,结果是select SUM(count) from all_online_info where time betwee2011/04/17 1:00 and 2011/04/17 1:10,如果我要获得select SUM(count) from all_online_info where time betwee ‘2011/04/17 1:00’ and ‘2011/04/17 1:10’怎么改呢?就是日期当字符处理
回复

使用道具 举报

千问 | 2011-4-18 05:30:17 | 显示全部楼层
<pre class=\"replyask-text\" id=\"content-4730184\">echo$sql=\'select SUM(count) from all_online_info where time betwee \"\'.date(\"Y/m/d\",strtotime(\"-1 day\")).\' \'.$i.

\':00\" and \"\'.date(\"Y/m/d\",strtotime(\"-1 day\")).\' \'.$i .\':10\"br\';
回复

使用道具 举报

千问 | 2011-4-18 05:30:17 | 显示全部楼层
<pre class=\"replyask-text\" id=\"content-4726806\">没用过这个方法,这样的判断直接加到WHERE后面么?我是要选取前一天每个小时的记录然后打印出来
回复

使用道具 举报

千问 | 2011-4-18 05:30:17 | 显示全部楼层
<pre class=\"replyask-text\" id=\"content-4727129\">for($i=1;$i24;$i)

{
$r=\"select * from all_online_info where DAYOFYEAR(date(\"Y/m/d\")) -DAYOFYEAR(time)=0 andYEAR(date(\"Y\"))-YEAR(time)=0 and date(\"G\")-\".$i.\"=0 \";
mysql 运行查找

}
去吃饭了。
回复

使用道具 举报

千问 | 2011-4-18 05:30:17 | 显示全部楼层
<pre class=\"replyask-text\" id=\"content-4728100\">复制进去错误啊- -!!晕晕晕
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行