I am a little confused how to make this work. I have main categories where the parent_id is '0'. I have sub-categories where the parent_id matches the product_name_id of the parent product (ie. sub-category 40 matches main category product_name_id 40).
With me so far? 🙂
So my display has been to show only the categories and subcategories where something actually exists for it in the database.
Problem: if something exists for a subcategory, works fine, but this product is not associated with the main category above it. Therefore, I may have something listed under product_name_id 3, a sub-category of main category 40. But neither main cat 40 nor sub-cat 3 shows up because nothing is indicated as also existing in main cat 40.
The code thus far:
$sql_main1 = "SELECT DISTINCT categories.product_name, categories.product_name_id, categories.parent_id AS PARENT,
products.product_name_id
FROM categories, products
WHERE categories.product_name_id = products.product_name_id
ORDER BY categories.product_name";
$sql_main_result = mysql_query($sql_main1);
echo "DISTINCT PRODUCT NAMES:<BR>";
while ($row_main3 = mysql_fetch_array ($sql_main_result)) {
if ($row_main3[PARENT] == '0') {
echo "$row_main3[product_name] - $row_main3[PARENT]<BR>";
}
if ($row_main3[PARENT] != '0') {
echo " $row_main3[product_name] - $row_main3[PARENT]<BR>";
}
}
The results (category name - parent_id):
Accessories - 0
Area Rugs / Carpeting - 0
Chairs - 40
Children's Furniture - 0
Clocks - 0
Curios - 0
Dinettes - 0
Entertainment Centers - 0
Recliners - 0
Sofas - 40
Tables - 5
Any suggestions?