i have this code on joomla view php: (this code generate the months dropdown)
<form action="<?php echo JRoute::_('index.php?option=com_mycom'); ?>" method="post" name="adminForm" id="adminForm" class="modelList">
<select name="filter.search" class="inputbox" onchange="this.form.submit()">
<?php
for ($i = 0; $i <= 12; ++$i) {
$time = strtotime(sprintf('-%d months', $i));
$value = date('Y-m', $time);
$label = date('F Y', $time);
printf('<option value="%s">%s</option>', $value, $label);
}
?>
</select>
</form>
and i have a mysql table with row of "date" call "date" so what that i am looking for is - when i am select the month all the data from this month will load on this page
so how can i get it from the sql query? i try this code on model but that give me an error:
$search = $this->getState('filter.search');
if(!empty($search))
{
if(stripos($search, 'id:') === 0)
{
$query->where('id = '.(int) substr($search, 3));
}
else
{
$search = $db->Quote('%'.$db->escape($search, true).'%');
$query->where('(date LIKE '.$search.')');
}
}
i try this code:
if(!empty($search))
{
if(stripos($search, 'id:') === 0)
{
$query->where('a.id = '.(int) substr($search, 3));
}
else
{
$searchParts = explode('-', $search);
// day 1 of selected month
$searchStartDate = date('Y-m-d', mktime(0, 0, 0, $searchParts[1], 1, $searchParts[0]));
// day 0 of next month is last day of selected month
$searchEndDate = date('Y-m-d', mktime(0, 0, 0, $searchParts[1] + 1, 0, $searchParts[0]));
$query->where("(a.date BETWEEN '$searchStartDate' AND '$searchEndDate' LIKE '.$search.')");
}
}
but it return an error:
Fatal error: Call to a member function where() on a non-object in
on this line - $query->where("(a.date BETWEEN '$searchStartDate' AND '$searchEndDate' LIKE '.$search.')");