簡體   English   中英

代碼點火器在WHERE子句后追加IS NULL

[英]code igniter appending IS NULL after WHERE clause

我使用代碼點火器的方式來編寫查詢。 然而,它不起作用,當我肆意騷擾它時,showng我在我的查詢中添加了NULL。

$select_fields  = "id,name,created_by,keywords";
$where_field    = "FIND_IN_SET('$id','keywords')";

$this -> db_social -> select($select_fields);
$this -> db_social -> from('user_collection1');
$this -> db_social -> where($where_field);
$query  = $this->db_social->get();

錯誤顯示這樣的查詢

SELECT `id`, `name`, `created_by`, `keywords` FROM `user_collection1` WHERE FIND_IN_SET('11','keywords') IS NULL

您使用的SQL函數具有此語法FIND_IN_SET(needle, haystack) 第二個參數是一個字符串,您提供的字符串是“keywords”。 顯然字符串“11”不在字符串“keywords”中。

我想你可以通過不使用db->where()函數得到你需要的東西。 試一試。

$select  = "id,name,created_by,keywords WHERE FIND_IN_SET('$id', keywords)";

$this->db_social->select($select);
//don't need the ->from call since this uses a single table, put that name in ->get
$query  = $this->db_social->get('user_collection1');

暫無
暫無

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

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