CodeIgniter Forums
print product category and product in the same page - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: print product category and product in the same page (/thread-52121.html)



print product category and product in the same page - El Forum - 05-30-2012

[eluser]Bigil Michael[/eluser]
hi friens
i have 2 tables product category and product

i want to print the result like this

category(no.of product in that category)
eg: laptop(12)

can any one help me to write the query.

thanks in advance....


print product category and product in the same page - El Forum - 05-30-2012

[eluser]sanir[/eluser]
hi
use following code

Code:
$this->db->select('c.category_name, count(p.product_id)');
$this->db->from('tbl_product p');
$this->db->join('tbl_categroy c','p.categroy_id = c.category_id ','left');
$this->db->group_by('c.category_id');  
$query = $this->db->get();

// SELECT c.category_name, count(p.product_id)
// FROM tbl_product p
// JOIN tbl_category c ON p.category_id = c.category_id
// group by c.category_id

Thanks,
Nasir Ranta


print product category and product in the same page - El Forum - 05-30-2012

[eluser]Bigil Michael[/eluser]
thanks.