$all = $this->input->get('all');
if($all)
{
$keywords = $this->input->get('search');
$data['search'] = $keywords;
$this->session->set_flashdata('search', $keywords);
$query = "SELECT * FROM `investOffers`, `news`";
$counts = "SELECT count(*) as count FROM `investOffers`, `news`";
$first = false;
if($keywords)
{
$data['keywords'] = $keywords;
$this->session->set_flashdata('keywords', $keywords);
$keywords = explode(" ", $keywords);
foreach($keywords as $k)
{
if(!$first)
{
$query .= " WHERE investOffers.desc LIKE '% ".$k." %' OR investOffers.title LIKE '% ".$k." %'";
$query .= " OR news.desc LIKE '% ".$k." %' OR news.title LIKE '% ".$k." %'";
$counts .= " WHERE investOffers.desc LIKE '% ".$k." %' OR investOffers.title LIKE '% ".$k." %'";
$counts .= " OR news.desc LIKE '% ".$k." %' OR news.title LIKE '% ".$k." %'";
$first = true;
}
else
{
$query .= " OR investOffers.desc LIKE '% ".$k." %' OR investOffers.title LIKE '% ".$k." %'";
$query .= " OR news.desc LIKE '% ".$k." %' OR news.title LIKE '% ".$k." %'";
$counts .= " OR investOffers.desc LIKE '% ".$k." %' OR investOffers.title LIKE '% ".$k." %'";
$counts .= " OR news.desc LIKE '% ".$k." %' OR news.title LIKE '% ".$k." %'";
}
}
}
$page = $this->uri->segment(2);
if($page)
{
$query .= " ORDER BY investOffers.date DESC LIMIT ".$page.", 10";
$counts .= " ORDER BY investOffers.date DESC LIMIT 10";
}
else
{
$query .= " ORDER BY investOffers.date DESC LIMIT 10";
$counts .= " ORDER BY investOffers.date DESC LIMIT 10";
}
$data['query'] = $this->db->query($query);
$counts = $this->db->query($counts);
foreach($counts->result() as $q)
{
$count = $q->count;
break;
}
$config['base_url'] = base_url().'/search';
$config['prev_link'] = false;
$config['next_link'] = false;
$config['last_link'] = false;
$config['first_link'] = false;
$config['suffix'] = '?'.http_build_query($_GET, '', "&");
$config['cur_tag_open'] = '<strong><img src="'.IMAGE.'pagerArrow.png" class="pagerArrow" />';
$config['cur_tag_close'] = '</strong>';
$from = intval($this->uri->segment(2));
$config['per_page'] = 10;
$config['num_links'] = 5;
$config['uri_segment'] = 2;
$config['total_rows'] = $count;
$this->pagination->initialize($config);
$data['pager'] = $this->pagination->create_links();
$data['content'] = $this->load->view(SITE.'search', $data, true);
$this->load->view(SITE.'layout', $data);
return true;
}
所以這是一個搜索查詢,首先我們檢查一下搜索是否是「全部」,這意味着搜索的所有網站,所以然後我做一個由空格分隔的關鍵字數組,輸入表單,所以然後我把它放在視圖中的preg_match的flash會話中,這是爲了preg_match在生成結果的視圖中突出顯示文本,所以然後我使查詢的串聯添加更多的LIKE,所以問題是當我輸入1個關鍵字時,它給了我不同的結果和它的okey,但是當我輸入2或多個關鍵字時,它給了我相同的結果,我的意思是結果列表完全相同,我不明白爲什麼是這樣,在它的視圖中所有沒關係,問題是在這個地方的代碼,我試圖在查詢中設置第DISTINCT關鍵字,但它並沒有幫助...爲什麼我會得到相同的結果?
個PS:這就是笨,MVC,這是一個控制器,我不使用的機型,因爲我不想打開多個文件:)
爲什麼你不看看生成的查詢,看看有什麼不對嗎?這段代碼長得太大了,無法在週五晚些時候閱讀。 –
首先我看到你的SQL語句不對。你做了2個表的交叉連接,但沒有加入語句。'investOffers'和'news'表之間的關係是什麼? – bksi
沒有關係,它們是不同的表格,它是搜索所有網站的地方,以及我在哪裏可以看到生成的代碼以及如何查看問題所在?我只想在一個視圖中生成所有結果 – BlareStriker