Codeigniter select query with AND and OR condition

后端 未结 7 951
情话喂你
情话喂你 2020-12-04 01:55

I want a Codeigniter select query from a table with three conditions in .

1. wrk_fld_exc = 140
2. wrk_cs_sts = Open
3. wrk_dlvrd_sts = Delivered OR wrk_cl_st         


        
相关标签:
7条回答
  • 2020-12-04 02:03

    codeigniter uses its own syntax for OR claus in query

    $this->db->or_where('wrk_cl_sts','Success'); 
    

    to use AND in where clause use $this->db->where(''); twice

    0 讨论(0)
  • 2020-12-04 02:05
    $city=$params['search']['city']; 
    $like = "(location like '%$city%' or address like '%$city%' or city like '%$city%')"; 
    $this->db->where($like);
    
    0 讨论(0)
  • 2020-12-04 02:14
        $this->db->select("*");
        $this->db->from("table_name");
        if($condition1 != ''){
            $this->db->where('wrk_fld_exc', 140);
        }
        if($condition2 != ''){
            $this->db->where('wrk_cs_sts ', open);
        }
        //You can limit the results
        $this->db->limit(5);
        $q = $this->db->get();
        return $q->result();
    

    This is the basic structure of the query you can implement in this way in codeigniter. You can add conditions if you require.

    0 讨论(0)
  • 2020-12-04 02:19
     $this->db->where('wrk_fld_exc',140);
    
     $this->db->where('wrk_cs_sts','open');
    
     $where = '(wrk_dlvrd_sts="open" or wrk_cl_sts = "Success")';
    
     $this->db->where($where);
    
    0 讨论(0)
  • 2020-12-04 02:20
    $this->db->where ('attribute',$data['attribute']);
    $this->db->or_where ('attribute',$data['attribute']);
    $this->db->and_where ('attribute',$data['attribute']);
    
    0 讨论(0)
  • 2020-12-04 02:22

    You can code it like this:

           $this->db->where('wrk_fld_exc',140);
           $this->db->where('wrk_cs_sts','open');
           $where = '(wrk_dlvrd_sts="open" or wrk_cl_sts = "Success")';
           $this->db->where($where);
    
    0 讨论(0)
提交回复
热议问题