簡體   English   中英

CodeIgniter Active Record 不相等

[英]CodeIgniter Active Record not equal

在使用活動記錄的 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);

一切都沒有運氣。 想法?

根據手冊,這應該有效:

自定義鍵/值方法:

您可以在第一個參數中包含運算符以控制比較:

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

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

它對我很好,

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

或者試試這個,

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

或者試試這個,

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

一切都會好起來的。

同樣的事情發生在我身上。我沒有在操作員面前放置空間。 可能是你得到了同樣的錯誤。

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

試試這個代碼。 這在我的情況下似乎有效。

$this->db->where(array('id !='=> $id))
$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_not_in('emailsToCampaigns.campaignId', $campaignId);
$this->db->select('*')
->from($this->table_proposals)
->where('customer_id', $this->session->userdata('user')['customer_id'])
->where('status <>' , 'draft')
->get()->result();

這是 codeigniter 文檔中的一個示例

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM