CodeIgniter Active Record not equal

matt picture matt · Mar 7, 2011 · Viewed 126.5k times · Source

In CodeIgniter using active record, how do I perform a not equal to in $this->db->where(). For instance:

$this->db->where('emailsToCampaigns.campaignId', $campaignId);

Will do equal to, but I need not equal to. I have tried:

$this->db->where('emailsToCampaigns.campaignId <> ', $campaignId);
$this->db->where('emailsToCampaigns.campaignId != ', $campaignId);
$this->db->where('emailsToCampaigns.campaignId', ' != ' . $campaignId);
$this->db->where('emailsToCampaigns.campaignId != ' . $campaignId);

All with no luck. Ideas?

Answer

Kevin Peno picture Kevin Peno · Mar 8, 2011

According to the manual this should work:

Custom key/value method:

You can include an operator in the first parameter in order to control the comparison:

$this->db->where('name !=', $name);
$this->db->where('id <', $id);
Produces: WHERE name != 'Joe' AND id < 45

Search for $this->db->where(); and look at item #2.