我正在开发一个用于每小时预订资源的系统。例如按小时或其他方式预订会议室。我几乎已经让所有功能正常工作,但有些事情远非完美,而且我有一个功能让我很烦恼。它正在预订一整周的资源。我的代码如下,但任何有助于提高效率的帮助将不胜感激。
谢谢!
史蒂夫
function bookweek($week) {
global $deskid, $date, $time, $member_id, $bookingTimes, $day0, $day1, $day2, $day3, $day4, $day5, $day6, $day7, $day8, $day9, $day10, $day11, $day12, $day13;
dbconnect();
switch($week) {
case 1:
$dupecheck = mysql_query("SELECT * FROM booked where deskid='$deskid' AND date>='$day0' AND date <'$day7'");
if (mysql_num_rows($dupecheck) == 0)
{
for($j = 0; $j< 7; $j++)
{
$daynumber=$j;
$testing = "day".$daynumber;
$daytotal= $$testing;
for($i = 1; $i < count($bookingTimes)+1; $i++)
{
$sql="INSERT INTO booked (date, time, deskid, member_id) VALUES ('$daytotal', '$i', '$deskid', '$member_id')";
$result = mysql_query($sql);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
}
}
}
break;
case 2:
$dupecheck = mysql_query("SELECT * FROM booked where deskid='$deskid' AND date > '$day6'");
if (mysql_num_rows($dupecheck) == 0)
{
for($j = 0; $j< 7; $j++)
{
$daynumber=$j+7;
$testing = "day".$daynumber;
$daytotal= $$testing;
for($i = 1; $i < count($bookingTimes)+1; $i++)
{
$sql="INSERT INTO booked (date, time, deskid, member_id) VALUES ('$daytotal', '$i', '$deskid', '$member_id')";
$result = mysql_query($sql);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
}
}
}
break;
}
}