2017-09-26 81 views
2

我有一個模型,我已經加入了兩個表,並選擇了一些表值,然後我把它傳遞給我的控制器,並從控制器我是將它傳遞給查看頁面。在查看頁面中,我使用foreach()來獲取值,然後顯示它。但是問題在於同一張桌子連續反覆重複。使用foreach()後,一次又一次重複相同的數據庫表的值

型號

public function image_list() 
{ 
    $this->db->select('interior_testing.type_id,interior_testing.profile_pic, interior_testing.type, interior_testing.location, interior_testing.name, interior_image_testing.image_path'); 
    $this->db->from('interior_testing'); 
    $q=$this->db->join('interior_image_testing', 'interior_image_testing.type_id = interior_testing.type_id'); 
    $this->db->where('interior_testing.category_id', 3); 
    $q = $this->db->get(); 
    return $q->result(); 
} 

控制器

public function index() 
{ 
    $this->load->model("Interior_listing_model","interior"); 
    $data['particles'] = $this->interior->image_list(); 

    // Load Interior Listing View 
    $this->load->view("interior/interior",$data); 
} 

查看

<?php foreach($particles as $particle): ?> 
    <div class="col-lg-4 col-md-4 col-sm-4 col-6 workimg"> 
    <img src="assets/img/<?= $particle->image_path ?> " width="100%"> 
    </div> 
<?php endforeach; ?> 
+0

你正在嘗試'$ this-> db-> get_compiled_select('interior_testing')'? –

+0

不,我只是試圖獲取數據庫表的值,這是我加入這兩個表後得到的。 – Shantanu

+0

上面的代碼是你需要打印的函數,導致這個函數打印查詢你試圖發送到後端和數據庫 –

回答

0

清理您的查詢像的下方,如果不工作,您可能需要一個GROUP_BY ID添加到您的查詢

public function image_list() 
{ 
$select = "it.type_id, it.profile_pic, it.type, it.location, it.name, im.image_path"; 

return $this->db->select($select) 
//equivalent to name as abr 
->join('interior_image_testing im', 'im.type_id = it.type_id'); 
->where('it.category_id', 3); 
//equivalent to name as abr 
->get('interior_testing it')->result(); 

} 
相關問題