Codeigniter活动记录:大于语句

ste*_*tef 18 php activerecord codeigniter

我正在尝试将"大于"where语句转换为CI的Active Record语法.当我使用这个片段

    $this->db->join('product_stocks', "product_stocks.size_id_fk = product_attributes.id", "left");
    $this->db->where('product_stocks.stock_level', '> 1');      
    $result = $this->db->get('product_attributes')->result_array();
Run Code Online (Sandbox Code Playgroud)

然后打印$ this-> db-> last_query(); 显示WHEREproduct_stocks .stock_level = '> 1'当然不正确.可以这样做吗?

小智 63

我认为这应该可以解决问题:

$this->db->where('product_stocks.stock_level >', '1');  //moved the >
Run Code Online (Sandbox Code Playgroud)


小智 7

$this->db->where('product_stocks.stock_level >', '1');
Run Code Online (Sandbox Code Playgroud) 要么
$this->db->where(array('product_stocks.stock_level >'=>'1'));
Run Code Online (Sandbox Code Playgroud) 应该这样做.注意字段名称和运算符之间的空格; 否则你最终会得到错误1064.