[eluser]Roy MJ[/eluser]
Hi.. Im dealing with a live site and i cant figure out a way around this. I have two tables. One is product_category and other one is products. Both are joined by a field category_id. What i need is to display all categories in client side while displaying also a single image from the corresponding page. When i tried to get the photo from products page by joining both tables matched by category_id, even though images are displayed, the same category is displayed many times. Pls help and its urgent…
My controller is as follows :
Code:
$config['per_page'] = 10;
$config['total_rows'] = $this->Products_model->get_total();
$config['base_url'] = site_url().'/products/index/';
$config['uri_segment'] = 3;
$this->data['total_products'] = $this->Products_model->get_all($config['per_page'], $pgoffset);
$this->data['pgoffset'] = $pgoffset;
$this->pagination->initialize($config);
$this->data['pagetitle'] = 'Products';
$this->load->view('products_category',$this->data);
}
My model page is as follows :
Code:
function get_total()
{
$this->db->select('COUNT(category_id) AS total');
$this->db->distinct();
$this->db->from('product_category');
$result_total = $this->db->get();
if($result_total->num_rows()>0){
$row = $result_total->row();
$count = $row->total;
}
return $count;
}
function get_all($limit, $pgoffset)
{
$this->db->limit($limit, $pgoffset);
$this->db->distinct();
$this->db->select('product_category.category_id,product_category.category_name,product.photo');
$this->db->from('');
$this->db->join('product', 'product.category_id = product_category.category_id');
$result_product = $this->db->get();
return $result_product->result();
}
And my view part is as follows :
Code:
<?php foreach($total_products as $row) { ?>
<div id="productcategory">
<img src="<?php echo base_url();?>images/arrowbullet.png" /> <a >category_id?>"><?= $row->category_name;?></a>
<br />
<?php /*?> <a >category_id?>"><img >photo?>" /></a><?php */?>
</div>
<?php }?>
<div><?php echo $this->pagination->create_links(); ?></div>
Is it possible to take up all values from the category table and corresponding photo values from the product table...??.. What i got is all the photos in the products page and the category name was repeated the no of times corresponding product was there in the table.