0
從窗體中獲得特定單詞後。我想從數據庫中的多個表中獲得像這個詞這樣的結果。CodeIgniter - 搜索結果 - 如何從多個表中返回特定單詞的搜索結果?
function search(){
$search = $this->input->post('searchword');
$this->db->select('articles.title, articles.post');
$this->db->select('files.name, files.desc');
$this->db->select('news.title, news.post');
$this->db->select('projects.title, projects.desc');
$this->db->from('articles, files, news, projects');
// I think problem is here
$like = array('articles.title' => $search,'articles.post' => $search,
'files.name' => $search,'files.desc' => $search,
'news.title' => $search,'news.post' => $search,
'projects.title' => $search, 'projects.desc' => $search);
$this->db->like($like);
return $this->db->get();
}
+ 1在複雜查詢中使用查詢 – amd
我同意在適當的查詢中創建複雜的連接,但即使您使用CI的連接,我99%的肯定也不會以OP的方式工作。你必須使用$ this-> db-> join,在from中有多個表將不起作用,因爲沒有辦法連接所描述的表。 –
是......因此建議使用一些東西來建立它......我一旦需要除了簡單的選擇以外的任何東西,我總是繞過CI的活動記錄的東西。 – Brian