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

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..

function get_all_galleries($query_array, $limit, $offset) {
        $query = $this->db->select("id, datum, title, folder_name")
                              ->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

$this->db->where('MONTH(`datum`)', $query_array['evek'], FALSE);

[quote author="noctrum" date="1306165131"]
$this->db->where('MONTH(`datum`)', $query_array['evek'], FALSE);

Oh yeah, the pros know all Smile thanks

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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