Codeigniter or_where不与or_like一起使用

时间:2014-07-04 08:01:17

标签: codeigniter

$ this-> db-> or_where($ where);它不起作用..它没有返回和值..但是当我删除or_like()语句时它工作得很好..可以&or -where和or_like一起工作吗?请帮忙..

    public function search(){

    $capacity1 = $this->input->post('capacity1');
    $capacity2 = $this->input->post('capacity2');
    $capacity3 = $this->input->post('capacity3');
    $capacity4 = $this->input->post('capacity4');
    $gender = $this->input->post('gender');
    $establishment_type = $this->input->post('type');
    $price = $this->input->post('price');

    $cprice = intval($price);


    if($price == "1499"){
      echo "1499";
    $where = "price < 1500";

    $this->db->or_where($where);
  }


    $this->db->or_like('capacity', $capacity1);
    $this->db->or_like('capacity', $capacity2);
    $this->db->or_like('capacity', $capacity3);
    $this->db->or_like('capacity', $capacity4);
    $this->db->or_like('type', $establishment_type);
    $this->db->or_like('gender', $gender);


    $query = $this->db->get('establishment');




    return $query->result_array();


}

2 个答案:

答案 0 :(得分:0)

使用where()代替or_where()。然后你的代码会产生类似的东西:

&#34; WHERE price < 1500 or capacity LIKE '%yourcapacity' ....等&#34;

答案 1 :(得分:0)

我得到了这个答案..

 if (count($this->ar_like) > 0)
        {
            if (count($this->ar_where) == 0)
            {
                $this->ar_like[0] = str_replace(array('OR','AND'),'',$this->ar_like[0]);
            }

            $sql .= implode("\n", $this->ar_like);
        }  

有关详细信息,请访问此主题 https://ellislab.com/forums/viewthread/99235/#501303