【发布时间】:2011-10-20 09:54:46
【问题描述】:
我正在尝试制作一个将输出以下内容的循环:
08:00
08:15
08:30
08:45
09:00
09:15
09:30
09:45
我需要它从 08:00 到 17:00
这是我目前的代码:
function echo_datelist ($i, $j, $day, $month, $year)
{
$time = str_pad($i, 2, '0', STR_PAD_LEFT).':'.str_pad($j, 2, '0', STR_PAD_LEFT);
$date = strtotime("$month $day $year $time:00");
$sql = mysql_query("select b.room_type, c.name from bookings as b, customers as c where b.the_date='$date' and b.id_customer=c.id");
echo $time.'<br />';
}
for ($i = 8; $i <= 16; $i++)
{
for ($j = 0; $j <= 45; $j+=15)
echo_datelist($i, $j, $day, $month, $year);
echo_datelist(17, 0, $day, $month, $year);
}
问题是,它在每小时之间输出一个 17:00,例如:
08:00
08:15
08:30
08:45
17:00
09:00
09:15
09:30
09:45
17:00
【问题讨论】:
-
将您的最后一个
echo_datelist呼叫移到for $i循环之外