Im working on a project that needs the following query but i couldn't get it done.
DATABASE: evenstdb
--------------------------------------
| Event_id | startDate | endDate |
--------------------------------------
|82637 |01-02-2020 | 02-03-2020 |
--------------------------------------
|66363 |10-03-2020 | 31-11-2020 |
--------------------------------------
i have a page that i should list the event according to the selected date range. everything works fine but the problem is that sometimes i get the same event listed twice because I'm listing the events according to the startDate
and the endDate
at the same time. sometimes the start and the end date are in the selected date range. How can i display an event only once?
my code:
// $date1 and $date2 are date inputs from the form
$query = $this->db->where('startDate >=', $date1);
$query = $this->db->where('startDate <=', $date2);
$query = $this->db->get('evenstdb');
$results1 = $query->result();
$query = $this->db->where('endDate >=', $date1);
$query = $this->db->where('endDate <=', $date2);
$query = $this->db->get('evenstdb');
$results2 = $query->result();
$data["eventsList"] = array_merge($results1,$results2);