У меня есть таблица ниже в базе данных.
id | list_id |venue_id |name | start_date | end_date |start_time | end_time
1 | 1 | 1 |asdf | 2019-02-02| 2019-02-28 |05:30 |10:00
2 | 7 | 2 |awed | 2019-02-10| 2019-02-20 |07:30 |14:00
3 | 7 | 1 |mjgd | 2019-02-04| 2019-02-13 |09:30 |18:00
Теперь я должен найти начальную и конечную дату venue_id=1
в диапазоне от 2019-02-04
до 2019-03-01
.Поэтому я использовал запрос ниже.
SELECT * FROM `batch_list` WHERE `venue_id` = 1 and ((start_date between '2019-02-04' and '2019-03-01') OR (end_date between '2019-02-04' and '2019-03-01'))
Теперь я должен найти дату и время venue_id = 1, который находится в диапазоне от 2019-02-04
и 2019-03-01
и 05:00
до 18:00
.Итак, я попытался выполнить запрос ниже
SELECT * FROM `batch_list` WHERE `venue_id` = 1 and ((start_date between '2019-02-04' and '2019-03-01') OR (end_date between '2019-02-04' and '2019-03-01')) and((start_time <= `end_time`) and (`start_time` between '05:00' and '18:00')and (end_time between '05:00' and '18:00'))
Так что до сих пор проблем не было.
У меня есть время, которое составляет от 05:00
до 20:00
, тогда я получаю все записи ссвязано с venue_id 1, но если я изменю время 10:00
на 13:00
, тогда я не получу записи.
Мне нужно выяснить, есть ли время начала и окончания, и время окончания доступно в диапазоне илине.Если найдены, проверьте дату начала и конец.
Не могли бы вы помочь мне в этом вопросе?
Модель
function fetchBatches($venue_id,$new_batch_start_date,$new_batch_end_date,$new_batch_start_time,$new_batch_end_time)
{
$where="batch_venue_id='$venue_id' and ((start_date between '$new_batch_start_date' and '$new_batch_end_date')OR (end_date between '$new_batch_start_date' and '$new_batch_end_date')) and ((start_time<=end_time) and (start_time < '$new_batch_start_time' and start_time < '$new_batch_end_time'))";
$result =$this->db->select('*')
->from('batch_list')
->where($where)
->get()
->result();
if ($result) {
return $result;
}
else{
return 0;
}
}