我被卡住了,我想这是一个循环问题,有人能在这里帮我,告诉我我做错了什么吗?这就是我所拥有的:
$this->time = mktime(7,0,0,$this->date);
for($i=1;$i<56;$i++) {
echo '<tr><td>' . date('H:i', $this->time) . '</td>';
while($this->results = $this->sql->fetch(PDO::FETCH_ASSOC)){
if (date('H:i:s', $this->time) != $this->results['time']) {
$this->agenda = '<td>' . $this->results['name'] . '</td></tr>';
} else {
$this->agenda = '<td>This Hour is free</td></tr>';
}
echo $this->agenda;
}
$this->time += 900;
}
我想做的是:使用24小时格式显示从早上7点到晚上8点30分的时间范围,而且小时应该每15分钟划分一次,这就是为什么我在900上增加了for循环。在与数据库匹配的小时上,显示人员的姓名,其他方面显示"此小时"是免费的。
但我在餐桌和餐桌上有点麻烦感谢并感谢
我希望这可能有用——它使用了DateTime
、DateTimeZone
和DateInterval
类,但没有包含您的代码来检查数据库结果——这应该相当简单。
<?php
define('BR','<br />');
$df='H:i';
$timezone=new DateTimeZone('Europe/London');
$interval=new DateInterval('PT15M');
$ts=date( 'Y-m-d H:i:s', strtotime('6.45am') );
$tf=date( 'Y-m-d H:i:s', strtotime('8.30pm') );
$start=new DateTime( $ts, $timezone );
$end=new DateTime( $tf, $timezone );
while( $start->add( $interval ) <= $end ){
echo $start->format( $df ) . BR;
}
$timezone=$interval=$ts=$tf=$start=$end=null;
?>