Codeigniter-如何根据日期和时间在会议室应用程序中获取可用会议室

时间:2018-07-23 12:12:53

标签: php mysql codeigniter

在开发会议室预订系统时,我在检索可用会议室时遇到错误。

数据库结构为:

表:Meeting_room_bookings

列:id(int),meeting_room_id(int),日期(以MM / DD / YYYY格式的日期),start_time(int),end_time(int)

下面是我的查询,如何根据日期和时间获得可用的房间?

  $this->db->select('meeting_room_id');
  $this->db->from('meeting_room_bookings');

  $this->db->where('date',$date);
  $this->db->where('start_time',$timestamp_start);
  $this->db->or_where('start_time',$timestamp_end);
  $this->db->or_where('end_time',$timestamp_start);
  $this->db->or_where('end_time',$timestamp_end);

  $where1 = "('start_time' <= $timestamp_start) AND ('end_time' >= $timestamp_start)";
  $where2 = "('start_time' <= $timestamp_end) AND ('end_time' >= $timestamp_end)";

  $this->db->or_where($where1);
  $this->db->or_where($where2);

  $data['value1'] = $this->db->get()->result();

表结构-https://i.stack.imgur.com/5HpnK.png

1 个答案:

答案 0 :(得分:0)

if you want to get available meeting rooms you can set a tag 0 for free and 1 for busy for your meeting rooms, if someone book a meeting room set a tag to 1 and then on meeting completion set tag to 0.