将新时隙添加到时隙表

时间:2016-06-15 06:57:04

标签: mysql if-statement join sql-order-by workbench

我正在制作派对预订系统,用户可以通过输入时段安排派对。如果用户输入现有时隙之间的时隙,则不应添加。 例如:我们预订时间为上午10:00至中午12:00,如果新用户需要预订派对,则时段表不应接受上午10:00至中午12:00之间的时间,也不应接受上午9:30至上午11:00也不应该接受上午10:00至下午12:30以及上午10:00至上午11:00

1 个答案:

答案 0 :(得分:0)

你应该在表格中使用两列作为开始时间,一列作为结束,

//get this values from the db using a select statement
$start=$_POST['start_time']

$end=$_POST['end_time']
//get id from db using select statement 
$id=$_POST['id']



INSERT INTO table_party(start_time, end_time)
SELECT id FROM table_party
WHERE id='$id AND (start_time BETWEEN $start AND DATE_SUB($start,INTERVAL 30 MINUTE ))
AND (end_time BETWEEN $END AND DATE_SUB($end,INTERVAL 60 MINUTE ));
相关问题