函数FIND_IN_SET()在codeigniter中不起作用

时间:2016-11-05 11:43:16

标签: codeigniter

函数FIND_IN_SET()适用于本地但不在服务器上运行。当我通过调用控制器(控制器名称)加载company_by_category_model时,它会抛出错误

错误:

FUNCTION firstdial.FIND_IN_SET does not exist

SELECT * FROM (`company_information`, `user_information`) 
WHERE `FIND_IN_SET` ('16',company_category) 
AND company_information.allowstatus=1 
AND company_information.delstatus=0 
AND company_information.user_id=user_information.user_id 
ORDER BY `company_id` desc

Filename: C:\wamp\www\firstdial\system\database\DB_driver.php
Line Number: 331

代码:

function company_by_category_model($category_id)
{   
    $this->db->select('*');
    $this->db->from('company_information,user_information');
    $search="FIND_IN_SET ('$category_id',company_category) 
        AND company_information.allowstatus=1 
        AND company_information.delstatus=0 
        AND company_information.user_id=user_information.user_id";
    $this->db->where($search);
    $this->db->order_by('company_id','desc');
    $query=$this->db->get();
    return $query->result();
}

3 个答案:

答案 0 :(得分:2)

您必须始终以某种方式检查FIND_IN_SET()函数的结果才能使其正常工作,请尝试以下操作:

  $this->db->where("FIND_IN_SET('$value',employer_job_location) !=", 0);

答案 1 :(得分:1)

function company_by_category_model($category_id)
{
    $this->db->select('*');
    $this->db->from('company_information,user_information');
    $search="FIND_IN_SET ('".$category_id."',company_category) 
        AND company_information.allowstatus=1 
        AND company_information.delstatus=0 
        AND company_information.user_id=user_information.user_id";
    $this->db->where($search);
    $this->db->order_by('company_id','desc');
    $query=$this->db->get();
    return $query->result();
}

尝试删除$category_id这是变量的单引号

答案 2 :(得分:0)

FIND_IN_SET()-此功能在您用逗号分隔的数据库中存储的值列表并要检查该逗号分隔的列表中是否存在值的情况下很有用。

示例:WHERE FIND_IN_SET( ‘yellow’, color list )