2012-07-13 45 views
0

我有以下笨模式功能: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活动记录来完成?

回答

3

一种可能性是:

$this->db->where('funding_goal <=', $amount_backed); 

另请参见CodeIgniter User Guide,搜索$this->db->where();,看看Custom key/value method,有以下例如:

$ this-> db-> where('id <',$ id);

P.S:还有两个更多的选择:关联数组方法自定义字符串

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; 
} 
相关问题