I'm working in CodeIgniter with a search from that will query the database.
The three fields are "Location" (dropdown list), "Date" (date) and "Event Type" (dropdown list).
The code I'm currently using is:
public function search_flyers($location, $date) {
$date = $this->utils_model->get_sql_date($date);
$query = $this->db->query("SELECT *, flyers.fid FROM flyers
LEFT JOIN event_dates ON flyers.fid = event_dates.fid
WHERE ((flyers.interval='weekly'
AND DATEDIFF('" . $date . "',flyers.start_date)%7=0
AND '" . $date . "' <= flyers.end_date)
OR (flyers.interval='fornightly'
AND DATEDIFF('" . $date . "',flyers.start_date)%14=0
AND '" . $date . "' <= flyers.end_date)
OR (flyers.interval='manual'
AND event_dates.date = '" . $date . "'
OR flyers.start_date = '".$date."'
AND '".$date."' <= flyers.end_date) AND flyers.approved = 1)
AND flyers.location = '".$location."'
GROUP BY flyers.fid
ORDER BY flyers.start_date ASC");
$data['flyers'] = $query->result();
$data['rows'] = $query->num_rows();
return $data;
The Event Date mentioned is being used in conjunction with the "interval" field to work out if an event falls on the date the user has searched for.
The event also has to be approved to be able to show in search results.
The problem is the form does not work if a user only fills in one field.
A previous developer has written this code, and I am charged with the task of making it work.
Normally I would change the AND flyers.location...
to OR flyers.location
, but that means it would return the results of either the date or the location you specified.