2014-01-07 29 views
-4

我知道這已被覆蓋,但我努力讓這個工作。我的數據庫結構如下:用codeigniter搜索多個mysql表格

照片

id 
title 
description 
file_name 

Photo_Category

id 
photo_id 
category_id 

分類

id 
name 

標籤

id 
tag_name 

Photo_Tags

id 
photo_id 
tag_id 

我想要做的就是讓別人輸入一個短語或關鍵字,然後我在數據庫中搜索該可能匹配結果標籤,類別,當然還有照片標題和說明,並返回結果的照片數據。

如果它有助於我在codeigniter中開發。

任何幫助將不勝感激。提前致謝。

+3

告訴我們你試過了什麼。 –

+0

PLZ支持新用戶,他們不智能以及我們所有 –

+0

你是否得到答案? –

回答

2
As my understand with your question 

The function in model 

function example($phrase) //select position 
    { 
     $this->db->select('*'); 
     $this->db->from('photo'); 
     $this->db->join('phototags', 'phototags.photo_id = photo.id', 'left'); 
       $this->db->join('tags', 'tags.id = phototags.tag_id', 'left'); 
       $this->db->join('Photo_Category', 'Photo_Category.photo_id = photo.id', 'left'); 
       $this->db->join('Categories', 'Categories.id = Photo_Category.category_id', 'left'); 
     $this->db->like('tag_name' , $phrase, 'after'); 
       $this->db->like('Categories.name' , $phrase, 'after'); 
       $this->db->like('photo.title' , $phrase, 'after'); 
       $this->db->like('photo.description' , $phrase, 'after'); 
     $query = $this->db->get(); 
     return $query->result_array(); 
    }