从joomla下拉开始的几个月的数据

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.')");

When working with DATE fields you should do just that. You are trying to work with it as a string, which is possible but very inefficient.

Instead of asking the database to return all records WHERE date LIKE '%2013-07%' you should be asking for all records between the beginning and end of the selected month.

SELECT *
FROM tbl
WHERE `date` BETWEEN '2013-07-01' AND '2013-07-31'

You can change your PHP code to something like this -

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("(date BETWEEN '$searchStartDate' AND '$searchEndDate')");
}