Question

Attempting to make sub menu filter based on relations in MySQL DB.

Main Groups: Drink, Food, Deli, Shelf Sub Groups: Coffee, Tea, Crisps, Asas

When using my LEFT JOIN query i am getting asas button appear multiple times.

Clearly i am not executing this in the correct way, what would be the ideal method to achieve the desired result.

Essentially the desired result would be when you click Drink button the sub nav filters and shows only drinks. This entire project is pre-loaded with ajax and rests heavily on ajax and classes.

The clear issue here currently is that there are multiple times the button asas appears... not the desired result.

Blue=Main Menu / Purple= Sub Menu

The MySQL

$sql7x = " SELECT * FROM items_sub_section_list 
                LEFT JOIN item_groups ig ON (items_sub_section_list.item_sub_sec_id=ig.item_sub_sec_id)
                WHERE items_sub_section_list.item_sub_sec_id>0
                ORDER BY items_sub_section_list.item_sub_sec_id ASC "; 

The Tables i have in the MySQL DB are:

items_section_list: 'sec_id' , 'title'

items_sub_section_list: 'item_sub_sec_id' , 'title'

item_groups: 'item_id' , 'section_id' , 'item_sub_sec_id'

I feel there may be a much better way to achieve the desired result. Perhaps a MySQL query based on a for each where perhaps? I am a little stumped to say the least on this.

Was it helpful?

Solution

I am assuming the parent id is in the sub-section table and the sub-section id is in the individual item table. I am also assuming a section only has one parent group and individual items are only in one sub-section.

SELECT ig.section_id, ig.select_textName,
  isl.sec_id, isl.sec_textName,
  issl.item_sub_sec_id, issl.individualItemName
FROM item_groups ig  
JOIN ON items_section_list isl (ig.section_id = isl.section_id)
LEFT JOIN ON items_sub_section_list issl (isl.sec_id = issl.sec_id)
            WHERE issl.item_sub_sec_id>0
            ORDER BY ig.select_textName, isl.sec_textName, issl.individualitemName,   
            issl.item_sub_sec_id ASC
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top