Welcome Guest, Not a member yet? Register   Sign In
Displaying Total Number Items Per Parent Category
#1

(This post was last modified: 01-19-2021, 08:22 AM by demyr.)

Hi there,

I have a foreach for products and as usual they all have a parent_category column.
I need to have the total number of products for each category but cannot get those numbers.

One of the examples I have tried so far:

PHP Code:
public function all_products($product_lang){
        $db      = \Config\Database::connect();
        $builder $db->table('products as p');
        $query $builder->select('*, p.product_category, count(p.product_category) as cat_total')
                ->where('p.product_lang'$product_lang)
                ->join('categories as c''c.category_id = p.product_category')
                ->groupBy('p.product_category')
                ->get();

                return $query->getResult();
                
     


Actually I get the numbers but as I group them, my foreach doesn't show every item. If I don't group them only 1 result returns.
Reply


Messages In This Thread
Displaying Total Number Items Per Parent Category - by demyr - 01-19-2021, 03:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB