[eluser]tim1965[/eluser]
Hi
I have a search function that allows a user to search between a start and end date. This works well. However if the user does not poulate the dates and hits submit the form generates a sql error.
I want to apply a default value to $this->input->post('start_date') so that if it isnt populated the query will run and would essentially bring back everything. I am thinking i need to use if(!isset), but cannot figure it out. any help appreciated.
My search function
function data_availability()
{
$start_date=$this->input->post('start_date');
$end_date=$this->input->post('end_date');
$current_date = date("Ymd");
$sql = "SELECT guestcal_entries_static.entry_id, guestcal_entries.object_id, guestcal_entries.class_id, guestcal_entries_static.from, guestcal_entries_static.to FROM guestcal_entries_static inner join guestcal_entries on guestcal_entries_static.entry_id = guestcal_entries.id
where guestcal_entries_static.from >= '$current_date'
and guestcal_entries.class_id in ('2', '3')
and `from` not between $start_date and $end_date
and `to`not between $start_date and $end_date";
$query = $this->db->query($sql);
if($query->num_rows() >0)
{
$row=$query->result_array();
return $row;