php CodeIgniter Active Record 不相等

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5226261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 20:41:00  来源:igfitidea点击:

CodeIgniter Active Record not equal

phpcodeigniter

提问by matt

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

在使用活动记录的 CodeIgniter 中,如何执行不等于 in $this->db->where()。例如:

$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?

一切都没有运气。想法?

回答by Kevin Peno

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.

搜索$this->db->where();并查看第 2 项。

回答by niro

Same thing occurred to me.I haven't put space before the operator. May be you're getting the same error.

我也发生了同样的事情。我没有在操作员之前放置空间。可能是你遇到了同样的错误。

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

回答by Raham

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.

一切都会好起来的。

回答by Eugine Joseph

Try this code. This seems working in my case.

试试这个代码。这在我的情况下似乎有效。

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

回答by jondavidjohn

$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.

要进行调试,您可能会在执行查询后立即放置此代码以查看它生成的确切 SQL,这可能会为您提供线索,您可以将其添加到问题中以允许进一步帮助。

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

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

回答by Vijendra Yadav

This should work (which you have tried)

这应该有效(您已经尝试过)

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