如何查看特定日期的预订ID? [英] How to check the id is booked of for specific days?
问题描述
我有一张桌子,记录如下表所示。
I have a table and records are like below table.
id | list_id |venue_id |name | start_date | end_date |start_time |end_time | days
1 | 1 | 1 |asdf | 2019-02-02 14:05:54| 2019-02-28 14:05:54|05:30 |10:00 | 1,2,3
2 | 7 | 2 |awed | 2019-02-10 15:02:24| 2019-02-20 15:02:24|07:30 |14:00 | 2,5
3 | 7 | 1 |mjgd | 2019-02-04 09:05:54| 2019-02-13 09:05:54|09:30 |18:00 | 4
现在我正在做的是如果在范围内找到,则必须检查开始时间和结束时间范围然后检查start_date和end_date是否在范围内(如果找到),然后显示记录。
Now What I am doing is I have to check the start_time and end_time range if found in the range then check start_date and end_date are in the range if found then display the records.
因此以下查询适用于上述情况
So below query is working for the above scenario
SELECT * FROM batch_list
WHERE venue_id=1 AND (start_date <= '2019-03-01') AND (start_time <= '13:00:00') AND (end_date >= '2019-02-04') AND (end_time >= '10:00:00')";
现在我有另一列是天
。所以我正在做的是 venue_id = 1
被预订为1 、、 2、3、4,然后显示记录。
Now I have one more column which is days
. So what I am doing is venue_id=1
is booked for a day which is 1,2,3,4 then display the records.
那么我如何检查ID为1的预定日期呢?
So how do i check the days which is already booked for id 1?
那么我要向用户查询什么以检查表中是否已经有场地ID = 1的日期?
So what query I have to the user it to check the days are already in the table or not of the venue id=1?
function fetchBatches($venue_id,$new_batch_start_date,$new_batch_end_date,$new_batch_start_time,$new_batch_end_time,$days)
{
$where="venue_id=$venue_id AND (start_date <= '$new_batch_end_date') AND (start_time <= '$new_batch_end_time') AND (end_date >= '$new_batch_start_date') AND (end_time >= '$new_batch_start_time')";
$result =$this->db->select('*')
->from('batch_list')
->where($where)
->get()
->result();
if ($result) {
return $result;
}
else{
return 0;
}
}
您能帮我这个忙吗
推荐答案
用于检查一个范围是否与另一个范围重叠的查询可能看起来像这样:
A query to check whether one range overlaps another might look like this:
SELECT x.*
FROM my_table x
WHERE x.start_datetime < :end_datetime
AND x.end\datetime >= :start_datetime;
但实际上您的问题比这更广泛
But really your question is broader than this
这篇关于如何查看特定日期的预订ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!