我有一张桌子
+---------------------+------+------+
| cdate | src | cnam |
+---------------------+------+------+
| 2016-02-24 00:57:41 | 1111 | aaaa |
+---------------------+------+------+
| 2016-02-24 00:58:33 | 2222 | bbbb |
+---------------------+------+------+
| 2016-02-24 01:43:54 | 1111 | cccc |
+---------------------+------+------+
| 2016-02-24 01:44:04 | 4444 | dddd |
+---------------------+------+------+
我确实从该表中选择了所有数据..
$source = '1111';
$theDate = '2016-02-24';
$query=mysql_query("SELECT * FROM myTb where src=".$source." and cdate >= '".$theDate." 00:00:00' AND cdate <= '".$theDate." 23:59:59' order by cdate ASC");
所以,我整天都在 $ query ,现在我需要每30分钟基于 cdate 循环这个数组..
编辑1
假设日期时间为2016-02-24 00:15:00
,第二个为2016-02-24 00:25:00
,第三个为2016-02-24 00:35:00
,我想只获得前两个,计算,然后我转到第3个一,等等。
while($row = mysql_fetch_array($query)){
if(**Condition**){
}
};
不幸的是,我不知道在IF的条件中输入什么内容!
或者是否有更好的想法。
提前致谢
答案 0 :(得分:0)
if ($query){
while( $row[] = mysql_fetch_array( $query ) );
$PostStartopen = $theDate.' 00:00:00';
$hh= 00;
sprintf("%02d", $hh);
for ($i = 0; $i < count($row)-1; $i++) {
for ($x = 1; $x <= 48; $x++) {
$PostOpenDate = strtotime($PostStartopen.' + '.$hh.' minute');
$hh += 30;
$PostCloseDate = strtotime($PostStartopen.' + '.$hh.' minute');
sprintf("%02d", $hh);
if($PostOpenDate <= strtotime($row[$i]['calldate']) && $PostCloseDate > strtotime($row[$i]['calldate'])){
// do stuff
error_log($row[$i]['cdate']." NEEDED date to calculate");
}
}
$PostStartopen = $theDate.' 00:00:00';
$hh= 00;
};
echo json_encode(array("res" => "success","output" => $output));
} else {
echo json_encode(array("res" => "error"));
};
但我认为这是一个更好的方法..