I am using Codeigniter + MySQL + Active Record and i am building a project with time periods for room prices.
I have the below schema in my mysql table
Package_periods
Room_package_prices
A package_id can have many periods as you can see in the example 01-08-17 to 08-08-2017, 10-08-2017 to 17-08-2017 etc.
For a given searched period (let's say 02-08-2017 to 14-08-2017), how can i find the package_id that not only exceeds the searched period but also there is not even 1 day outside of the searched period?
I mean, the package_id periods (from and to through multiple mysql rows), should cover ALL the days of a searched period without leaving a single gap.
public function getFHotels($checkin = null, $checkout = null, $adults = null, $packageType = null, $package_id = null, $limit, $start, $lang_id) {
$this->db->select('DISTINCT(hotels.hotel_id)')
->from('hotels')
->join('rooms', 'rooms.hotel_id=hotels.hotel_id')
->where('rooms.room_active', 1)
->where('hotels.hotel_active', 1)
->limit($limit, $start);
if ($packageType) {
$this->db->where('rooms.room_package_id', $packageType);
}
if ($package_id && $adults) {
//if $package_id is given, do not search for checkin-checkout
$this->db->join('room_package_prices', 'room_package_prices.room_id=rooms.room_id');
$this->db->where('room_package_prices.package_period_id', $package_id);
$this->db->where('room_package_prices.adults', $adults);
$this->db->where('room_package_prices.price>', 0);
} elseif ($checkin && $checkout && $adults) {
//if $checkin and $checkout is given, search for the period_from and period_to
//Here goes my actual question
}
$qry = $this->db->get();
if ($qry->num_rows() > 0)
return $qry->result_array();
return FALSE;
}

