我有兩個表 - 圖像和類別誰是這樣的:如何使用Codeigniter過濾db數據?
CREATE TABLE `categories` (
`id` int(11) NOT NULL,
`title` varchar(255) NOT NULL,
`user_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `images` (
`id` int(11) NOT NULL,
`categories_id` int(11) NOT NULL,
`file` text NOT NULL,
`caption` text NOT NULL,
`description` text NOT NULL,
`user_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
我有4類,我需要過濾和separatly每個類別
我嘗試喜歡這一點,但它的顯示圖像顯示所有圖像
**Model:**
public function org_filter()//filter categories
{
$this->db->select('i.file,i.categories_id,c.id,c.title',false);
$this->db->from('images as i');
$this->db->join('categories as c','i.categories_id = c.id','inner');//join tables based on the foreign key
$this->db->where('c.title','organizers');//set filter
$query = $this->db->get();//get data*/
return $query;
}
**Controller**
$data=array(
'r_images' => $this->Gallery_model->org_filter(),
);
$this->load->view('layouts/main', $data);
**View**
<h3 class="svgbg">ORGANIZERS</h3><!--name of the first category-->
<?php foreach($r_images->result() as $img) : ?>
<div>
<div class="thumbnail">
<?=img($img->file)?>
</div>
</div>
<?php endforeach; ?>
所以我的目標是從數據庫中進行dinamical fetch來查看。
P.S:對不起,壞的日本
未定義的變量:categoryId –