I'm using latest codeigniter
I'm trying to get all products from the db and all related items for each product. Haven't coded for a while so I got stuck on output..
Here's my model:
public function collections() {
$this->db->select('*');
$this->db->from('products');
$this->db->join('product_images', 'product_images.from_set = products.img_set_ref');
$this->db->order_by('products.id');
$q = $this->db->get();
if ($q->num_rows() > 0) {
return $q->result();
}
return false;
}
Controller:
public function products() {
$this->load->model('Frontend');
$page_data['results'] = $this->Frontend->collections();
$this->load->view('collections', $page_data);
}
This is the output I'm trying to get (example of two products):
<div class="pr"> //product 1
<a href="img/pr_1.jpg" rel="gallery01"><img src="img/pr.jpg" alt="">
</a>
<a href="img/pr_2.jpg" rel="gallery01"><img src="img/pr.jpg" alt="">
</a>
</div>
<div class="pr"> //product two
<a href="img/pr_12.jpg" class="fancybox" rel="gallery02"><img src="img/pr.jpg" alt="">
</a>
<a href="img/pr_22.jpg" class="fancybox" rel="gallery02"><img src="img/pr.jpg" alt="">
</a>
</div>
I can't figure out how to properly echo products in foreach loop in the view so that they were in structure like above. How to achieve that?