CodeIgniter Active Record not equal

PhpCodeigniter

Php Problem Overview


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?

Php Solutions


Solution 1 - Php

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.

Solution 2 - Php

It worked fine with me,

$this->db->where("your_id !=",$your_id);

Or try this one,

$this->db->where("your_id <>",$your_id);

Or try this one,

$this->db->where("your_id IS NOT NULL");

all will work.

Solution 3 - Php

Try this code. This seems working in my case.

$this->db->where(array('id !='=> $id))

Solution 4 - Php

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

This should work (which you have tried)

To debug you might place this code just after you execute your query to see what exact SQL it is producing, this might give you clues, you might add that to the question to allow for further help.

$this->db->get();              // your query executing

echo '<pre>';                  // to preserve formatting
die($this->db->last_query());  // halt execution and print last ran query.

Solution 5 - Php

This should work (which you have tried)

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

Solution 6 - Php

$this->db->select('*')
->from($this->table_proposals)
->where('customer_id', $this->session->userdata('user')['customer_id'])
->where('status <>' , 'draft')
->get()->result();

Solution 7 - Php

Here is an example from the codeigniter documentation

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmattView Question on Stackoverflow
Solution 1 - PhpKevin PenoView Answer on Stackoverflow
Solution 2 - PhpRahamView Answer on Stackoverflow
Solution 3 - PhpEugine JosephView Answer on Stackoverflow
Solution 4 - PhpjondavidjohnView Answer on Stackoverflow
Solution 5 - PhpVijendra YadavView Answer on Stackoverflow
Solution 6 - PhpAdeelView Answer on Stackoverflow
Solution 7 - Phpcolinam1992View Answer on Stackoverflow