使用Codeigniter查询检查房间可用性

时间:2019-02-22 09:57:28

标签: php sql codeigniter

我是Codeigniter的新手。 现在,我正在开发酒店房间预订系统。现在,我在预订时检查房间是否有空。

Booking Tabele database stracture

我查询房间空房的查询

$cindt = $this->input->post('myCheckInDate');
$coutdt = $this->input->post('myCheckOutDate');
$roomid = $this->input->post('room');
$this->db->select('*');
$this->db->from('booking');
$this->db->where("b_room", $roomid);
       $this->db->where('b_cin <= ',$cindt);
       $this->db->where('b_cout <= ',$cindt);
       $this->db->where('b_cout >= ',$coutdt);  
       $this->db->where('b_cin >= ',$coutdt);       
            $query = $this->db->get();
            $nn=$query->result_array(); 
                        //print_r($nn); exit();

    if($nn){
        $this->session->set_flashdata('yes', 'Rooms is not Available');
                    redirect($_SERVER['HTTP_REFERER']);
                }

1 个答案:

答案 0 :(得分:0)

$cindt = $this->input->post('myCheckInDate');
$coutdt = $this->input->post('myCheckOutDate');
$roomid = $this->input->post('room');

    $this->db->select('*');
    $this->db->where('b_cin >=', $cindt);
    $this->db->where('b_cout <=', $coutdt);
    $this->db->where('b_room', $roomid);
    $this->db->from('booking');
    $nn = $this->db->get()->result();

  if($nn > 0){
        $this->session->set_flashdata('yes', 'Rooms is not Available');
                    redirect($_SERVER['HTTP_REFERER']);
                }