笨。如何返回变量值大于数据库中字段的记录?

时间:2012-07-13 06:47:32

标签: php mysql codeigniter activerecord

我有以下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活动记录来完成这项工作?

2 个答案:

答案 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;
}