-2
$day1=date('d');
$add2 = strtotime("+ 1 day");
$day2=date('d', $add2);
$add3 = strtotime("+ 2 day");
$day3=date('d', $add3);
$add4 = strtotime("+ 3 day");
$day4=date('d', $add4);
$add5 = strtotime("+ 4 day");
$day5=date('d', $add5);
$add6 = strtotime("+ 5 day");
$day6=date('d', $add6);
$add7 = strtotime("+ 6 day");
$day7=date('d', $add7);

$month=date('m');
$year=date('Y');

$alltime=array("12:00PM", "12:30PM", "1:00PM","1:00PM","1:30PM","2:00PM","2:30PM","3:00PM","3:30PM","4:00PM","4:30PM","5:00PM","5:30PM","6:00PM","6:15PM","6:30PM","6:45PM","7:00PM","7:15PM","7:30PM","7:45PM","8:00PM","8:15PM","8:30PM","8:45PM","9:00PM","9:15PM","9:30PM","9:45PM");

$allday=array($day1,$day2,$day3,$day4,$day5,$day6,$day7);

foreach($alltime as $time)
{
    foreach($allday as $day)
    {
        $check="Select * From restaurant,reservation where restaurant.resid=reservation.resid and time='$time' and date='$year-$month-$day' and username='$username' and status='active'";
        $result=mysql_query($check);            
    }
}

我正在尝试创建具有特定时间的基本每周日历。下面的代码没有问题。唯一的问题是 $check 和 $result 保持相同的名称。

之后,我正在检查 mysql_num_row($result) 代码并执行它。但是没有运气......因为 $result 和 $check 应该不同

我想得到它们:

$check1=sql

$result1=$check1

$check2=sql

$result2=$check2

...

$check203=sql

$result=$check203

在 foreach 中格式化,这样我就可以接受它并用它做任何我想做的事情。

我用了

for($i; $i<=203; $i++)

foreach 结果很长很疯狂,但没有用。

那么如何使用唯一编号或任何可以彼此分开的东西来执行 $check 和 $result 呢?

4

1 回答 1

2

这种方式非常慢,并且会做很多没有结果的查询。更好的方法是查询所有预订,然后在 PHP 中填补没有找到预订的空白。

SELECT
    time, date, id, name, etc
FROM
    restaurant
    INNER
     JOIN reservation
       ON restaurant.resid=reservation.resid
WHERE
    date BETWEEN $start AND $end and username='$username' and status='active'

地点$start = date('d-m-Y', strotime('midnight'))和地点$end = date('d-m-Y', strtotime('+7 day, midnight'))

于 2013-05-12T18:38:53.343 回答