如何转换(从$ type ==' 1'&& $ type ==' 2')的用户中选择$ users;在codeigniter

时间:2015-03-17 14:36:16

标签: php codeigniter

所以我对codeigniter的背景很少,但我真的无法理解如何使用“or_where”和上面的问题。所以我的代码从这里开始:

function get_all(){
$this->db->where('type', '2');
$this->db->or_where('type ==', '2'); 
$query = $this->db->get('users');
$res = $query->result();
echo $res;
}

2 个答案:

答案 0 :(得分:1)

我认为你很亲密:

$this->db->select('users');
$this->db->from('user');
$this->db->where('type', '1');
$this->db->or_where('type ==', '2');
$query = $this->db->get();
$res = $query->result();

我没试过,但它应该有用。

答案 1 :(得分:0)

$array = array('type' => '1', 'type' => '2');

$this->db->where($array); 

$this->db->where可以将关联数组作为参数。因此将键和值作为关联数组传递。它会起作用。