HOW CAN I USE MYSQL COUNT function in Multiple tables?

I am still a php/mysql newbie and I am working on mysql table relationship concept and i am having an issue with using mysql count in multiple table.
Here is my db structure.

[php]product table
id product_name product_img groupeid
1 Sneaker Mark sneaker_adi.png 1
2 bag Eric bageric.png 2
3 Sneaker Etoi sneakeretoi.jpg 1[/php]

[php]groupe table
group_id group_name
1 men
2 women

category table
catid catname
1 sneaker-shoes
2 bag-woman

productcategory table
prod_id cat_ID
1 1
2 2
3 1
[/php]
What i want to do is to determine the number of sneaker-shoes using mysql.

We can see that the number of sneaker-shoes in the db is 2.

But how can i use count() in these multiple tables.

I tried like this;

[php]$sql = “SELECT COUNT(*) product.id,product_name,catname FROM product INNER JOIN productcategory ON product.id = prod_id
INNER JOIN category ON catid = cat_ID WHERE catname=‘sneaker-shoes’”;
[/php]

i got error like:
[php]Fatal error: Call to a member function execute() on a non-object in C:\wamp\www\kbashopping\Homme\index.php on line 32
[/php]

Hope i exposed the issue clearly, any help and assistance will be appreciate

Thanks

That isn’t as issue with count, although you are missing a coma in the query. That errors says you pdo object, isn’t currently an object.

Your group_id is not set up right. What if you have a product that is in multiple groups. You cant do it with your design. You need to do it just the way you have the productcategory setup (joiner table)

for the groupe…no problem…i will do it…thanks

Sponsor our Newsletter | Privacy Policy | Terms of Service