高级Codeigniter按多个关键字搜索

时间:2016-04-17 10:05:00

标签: search codeigniter-3

我想用codeigniter在数据库中搜索多个行中的一定数量的关键字。

我的代码如下所示:

$search = array('search goes here');
$keywords = explode(' ', $search);

        $this->db->like('nume', $search);
        $this->db->or_like('id', $search);
        $this->db->or_like('description', $search);
        $this->db->or_like('code', $search);
        $query = $this->db->get('property');
        $config['total_rows'] = $query->num_rows();
        $this->pagination->initialize($config);

        $this->db->like('nume', $search);
        $this->db->or_like('id', $search);
        $this->db->or_like('description', $search);
        $this->db->or_like('code', $search);
        $this->db->limit($config['per_page'], $this->uri->segment(4));
        $this->db->order_by('added_date', 'DESC');
        $query = $this->db->get("property");
        $properties = $data['properties'] = $query->result();

我想要的是:

foreach($keywords as $keyword) {
//some code that will search the database by each keyword
}

0 个答案:

没有答案