「users」、「products」、「product_types」という3つのテーブルがあります。 「ユーザー」テーブルには、サイトのユーザーに関するすべての通常のデータ(id
列を含む)が格納されます。 「製品」表には製品のproduct_id
、追加したユーザーのuser_id
、およびproduct_type
がリストされています。 'product_types'テーブルにはid
列( 'products'テーブルのproduct_type
int値に対応)とvarchar name
列があります。CodeIgniterで%likeとJOINを併用する
「ユーザー」テーブルで%like%
の検索を実行して、ユーザーが商品タイプを検索すると、検索した商品タイプに一致する商品を持つすべてのユーザーを表示するようにします。 - それは結果なしで戻ってくる他の回
$string = urldecode($string);
$this->db->select('users.*');
$this->db->from('users');
$this->db->like('users.company_name',$string,'both');
$this->db->or_like('users.address_1',$string,'both');
$this->db->or_like('users.city',$string,'both');
$this->db->or_like('users.contact',$string,'both');
$this->db->or_like('product_types.name',$string,'both');
$this->db->join('products','users.id = products.client_id');
$this->db->join('product_types','products.product_type = product_types.id');
$this->db->distinct();
$users = $this->db->get();
foreach($users->result() as $user){
// search result
}
私は、foreach文にこれを養う...しかし、それは最初の行だけの時間のほとんどを見せている:ここに私は現在、私のCodeIgniterのモデルに使用してんですよ。誰が私が間違っているのか教えていただけますか?
実行されたSQLクエリを表示する '$ this-> db-> last_query();を表示してください。 – Sukumar