Reputation: 299
I have the following codeigniter model function:
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;
}
I need to only get records where the variable $amount_backed
is higher or equal to the field 'funding_goal'
.
How can this be done with codeigniters active record?
Upvotes: 0
Views: 1784
Reputation: 16115
One possibility would be:
$this->db->where('funding_goal <=', $amount_backed);
Also see the CodeIgniter User Guide, search for $this->db->where();
and look at Custom key/value method
, there is following example:
$this->db->where('id <', $id);
P.s.: there are two more alternatives: Associative array method and Custom string.
Upvotes: 3
Reputation: 21462
you can use :
$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;
}
Upvotes: 1