选择多个变量列

时间:2012-12-20 16:49:37

标签: php mysql

我正在使用PHP制作餐厅预订模块。

问题在于我想让用户选择他们想来的时间以及想去的时间。

在这两次之间,需要占用表,因此在这些时间段内需要有一个名称。

我不知道如何完成这件事。

这是我现有的代码:

$day="0".$_POST['day'];
$month="0".$_POST['month'];
$year=$_POST['year'];
$date=$year ."-". $month ."-". $day;
$table=$_POST['table'];
$name=$_POST['name'];
$fromtime=$_POST['fromtime'];
$untiltime=$_POST['untiltime'];
$tablenumber = $table;

$host="localhost";
$user="root";
$password="root";
$database="restaurant";
$connection = mysql_connect ($host, $user, $password)
    or die ("could not connect with server");
$db = mysql_select_db ($database, $connection)
    or die ("could not connect with db");

$query = mysql_query("SELECT * FROM tables WHERE table='$tablenumber' AND date = '$date'");
?>

1 个答案:

答案 0 :(得分:1)

我猜你与预订表有一对多的关系(如果他们只能保留1个表),所以你需要一个插入语句来添加预订

这里有一些伪代码

INSERT INTO reservation (tableid, startTime,endtime,reservationName) VALUES (tableid, yourFronttime, yourEndTime, reservationName)

但在插入之前,你必须检查表格是否像这样免费

SELECT tableId
FROM reservation 
WHERE (startTime BETWEEN yourFrontTime AND untilTime) OR (endtime BETWEEN yourFrontTime AND untilTime) 
AND TableId = yourId

如果你得到那个选择的结果,他们必须选择另一个时间或另一个表。