Am building an E-commerce site but have run into some kind of issues
Problem
I have a category called drinks now under this category i have two sub categories which are whiskey and non-alcoholic. Under non Alcoholic we have juice and wine drinks in the parent category for whiskey and non-alcoholic while non-alcoholic is the parent category for juice and wine. the problem is when a user clicks on drinks i want them to be able to see all the items that are both in whiskey category and the children of non-alcholic category but my query to fetch the products in this categories and bring them together is not working.instead it is getting only the products of the parent category drinks which as no products
Code
public function select_from_product_page_all($cat,$level){
$que = $this->query("SELECT a.product_category_id,a.quantity, a.product_id, a.description, a.product_name, a.image, a.price, Deriv1.Count FROM `product` a LEFT OUTER JOIN (SELECT parent, COUNT(*) AS Count FROM `product_category` GROUP BY parent) Deriv1 ON a.product_category_id = Deriv1.parent WHERE a.product_category_id=" . $cat);
return $que;
}
Database Structure
Products Table Columns are
product_name,quantity,price,image,description,product_category_id
Product Category Table Columns are
product_category_id,name,parent
what ties the product to a category is product_category_id, what ties a product_category to a parent category is the parent column and what is saved in the parent column is the product_category_id of the parent.
Under non Alcoholic we have juice and wine drinks in the parent category for whiskey and non-alcoholic while non-alcoholic is the parent category for juice and wine.
is not clear at all, wine is non-alcoholic? Not too comment too much on your data, but really? Also, plz fix your code mark-up. Btw, have a read of this about handling category structures. Very interesting. – rkeet