我正试图创建一个搜索'功能到我的网站,我的查询有点复杂,因为它使用'加入'喜欢',' get_where'。以下是我到目前为止所尝试的内容,但不幸的是。
$business_where['b.active'] = '1';
$business_where['b.deleted'] = '0';
$input = $this->input->get('keyword',TRUE);
$this->db->select('*');
$this->db->join("category c", "c.category_id = b.category_id", "left");
$this->db->order_by('date_created', 'DESC');
$this->db->like('name',$input);
$query = $this->db->get_where('listing_businesses as b', $business_where );
$data['results'] = $query->result();
$this->load->view('elements/header',$data);
$this->load->view('pages/the_nominees', $data );
$this->load->view('elements/footer',$data);
上面的代码给了我一个空结果,但它假设返回一些结果,因为搜索关键字是正确的。有什么帮助,想法吗?
更新
将代码更改为
$this->db->select('*');
$this->db->join("category c", "c.category_id = b.category_id", "left");
$this->db->order_by('date_created', 'DESC');
$this->db->like('listing_title',$input);
$query = $this->db->get_where('listing_businesses as b', $business_where );
$data['page'] = 'nominees';
$data['results'] = $query->result();
它给了我想要的结果,但其余的结果都是重复的。有什么想法,请帮忙吗?
答案 0 :(得分:0)
get_where的语法是:
$query = $this->db->get_where('mytable', array('id' => $id), $limit, $offset);
在您的代码中,您应该检查
中的条件 $query = $this->db->get_where('listing_businesses as b',array ('$business_where' =>some value );