如何在codeigniter中使用Find_IN_SET?

时间:2018-12-20 11:47:05

标签: php codeigniter mysqli

public function job_fetch($key)
    {
        $this->db->select('*');
        $this->db->from('job');
        $where = "FIND_IN_SET(".$key.", job_title) and FIND_IN_SET(".$key.", city)";
        $this->db->where($where);
        $query = $this->db->get();
        $result = $query->result_array();
        return $result;
    }

在这段代码中,我传递了一个变量$key,其中$key是一个数组,看起来像Array ( [0] => java [1] => developer [2] => hibernate [3] => struts [4] => in [5] => mumbai [6] => noida [7] => delhi,我想通过job_title和{ {1}}如果值位于city中,那么我该如何解决?请帮助我。

谢谢

2 个答案:

答案 0 :(得分:0)

public function job_fetch($key)
    {
        $this->db->select('*');
        $this->db->from('job');
        $this->db->where("FIND_IN_SET(".$key.", job_title)");
        $this->db->or_where("FIND_IN_SET(".$key.", city)");
        $query = $this->db->get();
        $result = $query->result_array();
        return $result;
    }

答案 1 :(得分:0)

这是在代码初始化器中WHERE something AND something的操作方式:

$this->db->where("FIND_IN_SET(".$key.", job_title)");
$this->db->where("FIND_IN_SET(".$key.", city)");