Welcome Guest, Not a member yet? Register   Sign In
Problem with database query

I have 2 tables in database. 
I need to get from database all rooms in which there is no reservation in the hours and date given by me.

Quote:[font=Monaco, Consolas, Courier, monospace]id int(11)
name varchar(15)[/font]

Quote:id int(11)
room_id int(11)
date date
time_start time
time_finish time

My function: 

PHP Code:
public function get_free_rooms() {
   $date $this->input->post('date'true);
   $time_start $this->input->post('time_start'true);
   $time_finish $this->input->post('time_finish'true);

   $query $this->db->join('reservations','rooms.id = reservations.room_id','left')
       ->where('reservations.id IS NULL'nullfalse)
   $query $query->result();

   echo json_encode($query);

[font=Arial,]My reservations table is empty now. When I give data:[/font]

Quote:$date = 2019-05-29, $time_start = 10:00:00, $time_finish = 13:00:00

[font=Arial,][font=Arial,]result of query is an empty array and should return all rooms because there is no booking.[/font][/font]

After you run your query did you use

PHP Code:
$temp $this->db->last_query();


To see what your query looks like?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )


What does your query look like when it is executed? Also, why don't you have a from and to date? Is the user only allowed to have the room for 1 day?

(This post was last modified: 05-30-2019, 01:09 AM by mizkuskuz.)

@InsiteFX, $temp return this:

Quote:SELECT * FROM `rooms` LEFT JOIN `reservations` ON `rooms`.`id` = `reservations`.`room_id` and `reservations`.`date` = '2019-05-29' and `reservations`.`time_start`<='10:00' and `reservations`.`time_finish`>='13:00' WHERE reservations.id IS NULL

@php_rocs, yes. Reservations are only for one day.

Theme © iAndrew 2016 - Forum software by © MyBB