如何使用 CodeIgniter 的 where() 方法编写不相等条件?

发布于 2024-10-20 18:32:12 字数 555 浏览 1 评论 0原文

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

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

会等于,但我不需要等于。我已经尝试过:

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

都没有运气。有想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

够钟 2024-10-27 18:32:12

根据手册,这应该有效:

自定义键/值方法:

您可以在第一个参数中包含运算符以控制比较:

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

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

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.

绿萝 2024-10-27 18:32:12

它对我来说效果很好,

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

或者尝试这个,

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

或者尝试这个,

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

一切都会起作用。

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.

将军与妓 2024-10-27 18:32:12

试试这个代码。
这似乎适用于我的情况。

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

Try this code.
This seems working in my case.

$this->db->where(array('id !='=> $id))
哑剧 2024-10-27 18:32:12
$this->db->where('emailsToCampaigns.campaignId !=' , $campaignId);

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

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

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

echo '<pre>';                  // to preserve formatting
die($this->db->last_query());  // halt execution and print last ran query.
$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.
︶ ̄淡然 2024-10-27 18:32:12

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

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

This should work (which you have tried)

$this->db->where_not_in('emailsToCampaigns.campaignId', $campaignId);
葮薆情 2024-10-27 18:32:12
$this->db->select('*')
->from($this->table_proposals)
->where('customer_id', $this->session->userdata('user')['customer_id'])
->where('status <>' , 'draft')
->get()->result();
$this->db->select('*')
->from($this->table_proposals)
->where('customer_id', $this->session->userdata('user')['customer_id'])
->where('status <>' , 'draft')
->get()->result();
莫多说 2024-10-27 18:32:12

以下是 codeigniter 文档中的示例

在此处输入图像描述

Here is an example from the codeigniter documentation

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文