CodeIgniter Forums
Or in a select statement - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Or in a select statement (/thread-78796.html)



Or in a select statement - Knutsford - 03-11-2021

PHP Code:
function select($table_name$where_data){
            $this->db->select('*');
          $this->db->from($table_name);
          $this->db->where($where_data);
        
$this->db->order_by('id','DESC');
          $query $this->db->get();
        
// echo $str = $this->db->last_query();
          return $query->result();




If I want to do an "or" is this right


$user_data=$this->action->select("table", array("a"=>$a, "b"=>$b) or array("c"=>$c, "b"=>$b));



Thanks


RE: Or in a select statement - iRedds - 03-11-2021

Can you show the final SQL query you are expecting?


RE: Or in a select statement - Knutsford - 03-11-2021

something like 

select * from table where ( a = 'aa' and b = 'bb')  or (c = 'aa' and b = [font=Tahoma, Verdana, Arial, sans-serif]'bb'[/font])


RE: Or in a select statement - iRedds - 03-11-2021

Query grouping