CodeIgniter Forums
Or in a select statement - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Or in a select statement (/showthread.php?tid=78796)



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 = 'bb')


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

Query grouping