Combining `where` and `like` statements by using the CI activerecords

前端 未结 6 2250
一个人的身影
一个人的身影 2021-01-06 18:48

To cut a long story short: Is it possible and if it is - how can I build a query that looks somewhat like this one

SELECT * FROM a
    WHERE row = 1 AND 
            


        
相关标签:
6条回答
  • 2021-01-06 19:03
    $this->db->where('salary_range_min >= ',$salarymin)
    $this->db->where('salary_range_max <= ',$salarymax)
    $this->db->where('job_title like '.$title.'% or skill like %'.$title.'%');
    // OR */
    $this->db->where('job_title like '.$title.'% or skill like %'.$title.'%',FALSE);
    // OR */
    $this->db->where('job_title like '.$title.'% or skill like %'.$title.'%',NULL);
    

    Try this out

    0 讨论(0)
  • 2021-01-06 19:11

    You can use the following:

    $this->db->like('title', 'match', 'before');
    

    It will produce:

    WHERE `title` LIKE '%match' ESCAPE '!'
    
    0 讨论(0)
  • 2021-01-06 19:19

    Why dont you try this:

        $this->db->where("row = 1 AND 
            (other_row LIKE '%..%' OR another_row LIKE '%..%')");
    $this->db->get('a');
    

    It's how you can write custom WHERE in CI. If it is not what u r looking for, feel free to explain

    0 讨论(0)
  • 2021-01-06 19:23

    You can try this.

       $query = $this->db->select('*')
                ->from('a')
                ->where('row',1)
                ->where("(other_row LIKE '%%' OR another_row LIKE '%%' )")
                ->get();
    
    
        foreach ($query->result() as $row) {
            //do sth.
        }
    

    You can write custom query string (from active record class)

     Custom string:
     You can write your own clauses manually:
    
     $where = "name='Joe' AND status='boss' OR status='active'";
    
     $this->db->where($where);
    
    0 讨论(0)
  • 2021-01-06 19:25

    I also having problem with or_where so i simply make my custom query like

    $this->db->query("SELECT * FROM `a` WHERE `row`=1 AND (CONDITION1 OR CONDITION2)")
    
    0 讨论(0)
  • 2021-01-06 19:26
    $sql= "SELECT * FROM `a`
    WHERE row = '1' AND 
    (other_row LIKE '%" . $value . "%' OR another_row LIKE '%" . $value . "%')";
     $this->db->query($sql);
    
    0 讨论(0)
提交回复
热议问题