2

我正在制作一个日历系统,用户可以在其中进行预订(在不同的页面上)。在此页面上,用户单击相关框以选择新预订的开始时间。我正在检查现有预订的数据库,并使这些预订不可点击以防止重复预订。

我的问题是,为什么只有当天的第一个预订出现在桌子上?

变量是否$booked保持真实,因此不显示其他预订?我无法理解它!

MySQL:

$query="SELECT * FROM bookings WHERE DateBooked = '{$year}-{$month}-{$selectedday}' AND Approved = 1";
$result = mysql_query($query);
$todayarray = mysql_fetch_assoc($result);

和 PHP:

while ($room <= $roomcount) {
    echo "\n<div class=\"roomtimes\">";
    echo "\n<table border=1>";
    echo "\n<tr><th class=\"titlecell\">Room $room</th></tr>";
    $cellnum = 10;
    while ($cellnum <= 22) {
        if (($todayarray['StartTime'] <= $cellnum) && ($todayarray['EndTime'] >= $cellnum) && ($todayarray['Room'] == $room)) {
            $booked = true;
        } else {
            $booked = false;
        }
        echo "\n<tr>";
        if ($booked) {
            echo "\n<td class=\"blankcell";
        } else {
            echo "\n<td class=\"linkcell";
        }

        if ($selectedtime == $cellnum) {
            echo " selectedcell";
        }
        echo "\">";
        if ($booked) {
            echo "$cellnum:00 --BOOKED--";
        } else {
            echo "<a href=\"newbooking.php?m=$selectedmonth&d=$selectedday&t=$cellnum&r=$room\">$cellnum:00</a>";
        }
        echo "</td>";
        echo "\n</tr>";
        $cellnum++;
    }
    $room++;
    echo "\n</table>";
    echo "\n</div>";
}
echo "\n</div>";
?>
4

1 回答 1

0

问题是您只查看表中结果集的第一行。您只调用mysql_fetch_assoc($result)一次,此函数一次只返回一个结果行。您需要遍历$result从查询调用中获得的信息。您可以使用类似于此的 while 循环:

while ($row = mysql_fetch_assoc($result) {
   //this can be your php code from above 
} 
于 2013-02-24T15:51:11.397 回答