CodeIgniter Forums
[SOLVED] Query with filters - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [SOLVED] Query with filters (/showthread.php?tid=41990)



[SOLVED] Query with filters - El Forum - 05-23-2011

[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


[SOLVED] Query with filters - El Forum - 05-23-2011

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



[SOLVED] Query with filters - El Forum - 05-23-2011

[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