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
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')";
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.
So how do i check the days which is already booked for 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;
}
}
Would you help me out on this issue?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.