我有以下codeigniter模型函数:
function get_successful($project_id, $amount_backed){
$data = '';
$this->db->where('id', $project_id);
$this->db->where($amount_backed >= 'funding_goal'); //HELP HERE
$this->db->where('published', '1');
......
return $data;
}
我只需要获取变量$amount_backed
高于或等于字段'funding_goal'
的记录。
如何使用codeigniters活动记录来完成这项工作?
答案 0 :(得分:3)
一种可能性是:
$this->db->where('funding_goal <=', $amount_backed);
另请参阅CodeIgniter User Guide,搜索$this->db->where();
并查看Custom key/value method
,有以下示例:
$ this-&gt; db-&gt; where('id&lt;',$ id);
P.s。:还有两种选择:关联数组方法和自定义字符串。
答案 1 :(得分:1)
你可以使用:
$this->db->where("funding_goal < $amount_backed")
a < b == b>=a
function get_successful($project_id, $amount_backed){
$data = '';
$this->db->where('id', $project_id);
$this->db->where("funding_goal < $amount_backed"); //HELP HERE
$this->db->where('published', '1');
......
return $data;
}