Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在codeigniter中使用OR运算符_Php_Codeigniter 3 - Fatal编程技术网

Php 如何在codeigniter中使用OR运算符

Php 如何在codeigniter中使用OR运算符,php,codeigniter-3,Php,Codeigniter 3,我正在使用CodeIgniter,我想使用OR运算符从db获取记录,所以有人能帮助我如何在where子句中使用OR运算符吗 从数据库获取记录,其中代码等于12或21,状态为1 public static function front_page_ads() { $CI = & get_instance(); $array = array('status' => 1 , 'code'=>'12' OR 'code'=>'21');

我正在使用CodeIgniter,我想使用OR运算符从db获取记录,所以有人能帮助我如何在where子句中使用OR运算符吗

从数据库获取记录,其中代码等于12或21,状态为1

public static function front_page_ads() {
        $CI = & get_instance();
        $array = array('status' => 1 , 'code'=>'12' OR 'code'=>'21');
        $CI->db->where($array);
        $CI->db->order_by('id', 'DESC');
        $CI->db->limit(3);
        $q = $CI->db->get('international');
        $r = $q->result();
        return $r;
    }
像这样使用

    $array = array('status' => 1);
    $CI->db->where($array);
    $ci->db->where("(code='12' OR code='21' )");
    $CI->db->order_by('id', 'DESC');
    $CI->db->limit(3);
    $q = $CI->db->get('international');
    $r = $q->result();
或_其中:多个实例由或连接

    $CI->db->where($array);
    $ci->db->or_where("code='12'");
    $ci->db->or_where("code='21'");

有两种写入的方法

$where = "name='Joe' AND status='boss' OR status='active'";
$this->db->where($where); 
或者你可以使用

$this->db->where('name', $name);
$this->db->or_where('id', $id);
在代码中:

public static function front_page_ads() {
        $CI = & get_instance();
        $code_arr=array('12','21');
        $CI->db->where('status',1);
        $CI->db->where_in('code', $code_arr);
        $CI->db->order_by('id', 'DESC');
        $CI->db->limit(3);
        $q = $CI->db->get('international');
        $r = $q->result();
        return $r;
    }
希望有帮助。

简单地说: $this->db->where(“status”,“live”)->或_where(“status”,“dead”)


如果我的答案有用,请用绿色勾选,这对将来的用户参考很有用。@GauharAli
                               or
    $this->db->where("(status='live' OR status='dead')");