2017-09-26 82 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(); 

} 
相关问题