I want to see if the category_id of a product_id is within the parent_id.
The code I am doing does the following:
it takes an input from the user which is the category names separated by commas. It then checks to see if the products category_name is found within the array of category names input by the user. The code works, however it can only be used for bottom-level category names and not parent category names.
Here is the database query which then joins the different tables together by their similar keys:
PHP Code:$products_query = "SELECT p.products_id, p.products_model, pd.products_name, pd.products_description, p.products_image, p.products_tax_class_id, p.products_price_sorter, GREATEST(p.products_date_added, p.products_last_modified, p.products_date_available) AS base_date, m.manufacturers_name, p.products_quantity, pt.type_handler, pc.categories_id, cd.categories_name, c.parent_id
FROM " . TABLE_PRODUCTS . " p
LEFT JOIN " . TABLE_MANUFACTURERS . " m ON (p.manufacturers_id = m.manufacturers_id)
LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON (p.products_id = pd.products_id)
LEFT JOIN " . TABLE_PRODUCT_TYPES . " pt ON (p.products_type=pt.type_id)
LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " pc ON (p.products_id = pc.products_id)
LEFT JOIN " . TABLE_CATEGORIES_DESCRIPTION . " cd ON (pc.categories_id = cd.categories_id)
LEFT JOIN " . TABLE_CATEGORIES . " c ON (cd.categories_id = c.categories_id)
WHERE p.products_status = 1
AND p.product_is_call = 0
AND p.product_is_free = 0
AND pd.language_id = " . $languages->fields['languages_id'] ."
ORDER BY p.products_id ASC";
$products = $db->Execute($products_query);



