• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] Query with filters

#1
[eluser]predat0r[/eluser]
Hey,
I have a DATE (example: 2011-05-23) in my table and want to filter by year and month, with this date structure. I know (guess) I can use mysql MONTH() or DATE_FORMAT() functions but how to implement them?

I tried to put MONTH in the like or where statements but gets error, and DATE_FORMAT in the select, with no success..

My code snippet:
$query_array contains the filter options from dropdowns, for example evek = 2010, and honapok = 05

To be honest, filtering by year works, because there are only one 2010, but for month, 05 could be a month or a day, or a part of a year also..

Code:
function get_all_galleries($query_array, $limit, $offset) {
        $query = $this->db->select("id, datum, title, folder_name")
                          ->from('galeriak')
                              ->where('status', 'aktiv')
                          ->order_by('datum', 'DESC')
                          ->limit($limit, $offset);
                      
        if(strlen($query_array['evek'])) {
            $query->like('datum', $query_array['evek']);
        }
        
        if(strlen($query_array['honapok'])) {
            $query->like('datum', $query_array['honapok']);
        }

        $data['content'] = $query->get()->result();
....

thank you

#2
[eluser]danmontgomery[/eluser]
Code:
$this->db->where('MONTH(`datum`)', $query_array['evek'], FALSE);

#3
[eluser]predat0r[/eluser]
[quote author="noctrum" date="1306165131"]
Code:
$this->db->where('MONTH(`datum`)', $query_array['evek'], FALSE);
[/quote]

Oh yeah, the pros know all Smile thanks


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.