Codeigniter parentheses in dynamic Active Record query

后端 未结 8 1564
死守一世寂寞
死守一世寂寞 2020-12-05 23:38

I\'m producing a query like the following using ActiveRecord

SELECT * FROM (`foods`) WHERE `type` = \'fruits\' AND 
       `tags` LIKE \'%green%\' OR `tags`          


        
相关标签:
8条回答
  • 2020-12-06 00:17

    Just adding my successful solution:

    $this->db->where("(table.field = $variable OR table.field IS NULL)");
    
    0 讨论(0)
  • 2020-12-06 00:18

    One of best feature to save your query when you applying multiple where or_where clauses.

    $this->db->group_start();
    $this->db->where();
    $this->db->or_where();
    $this->db->group_end();
    

    Happy Coding. :)

    0 讨论(0)
提交回复
热议问题