Category arranging
Posted: Tue Aug 21, 2007 9:31 pm
I have a table that stores categories, but main categories and sub categories.
The table structure has two fields, main_category and category.
- If main_category is blank, then category is the main category.
- If main_category is not empty, then category is a sub-category of main_category
What I want to do is create a query that groups all of the sub-categories for each main category
example:
Main categories: main1, main2
Sub categories: sub1, sub2, sub3
Let's say sub1 is part of main1 while subs 2 & 3 are part of main2
After a query is run I want sub1 to be grouped under main1 and sub2 & 3 to be grouped under main2
Possibly the main categories could be column names and each value could be a sub-category
Is it possible to structure a query to do this? (or something similar)
Ultimately I want to gather this information into an array with this structure
The table structure has two fields, main_category and category.
- If main_category is blank, then category is the main category.
- If main_category is not empty, then category is a sub-category of main_category
What I want to do is create a query that groups all of the sub-categories for each main category
example:
Main categories: main1, main2
Sub categories: sub1, sub2, sub3
Let's say sub1 is part of main1 while subs 2 & 3 are part of main2
After a query is run I want sub1 to be grouped under main1 and sub2 & 3 to be grouped under main2
Possibly the main categories could be column names and each value could be a sub-category
Code: Select all
main1 | main2
--------------------
sub1 | sub2
| sub3Ultimately I want to gather this information into an array with this structure
Code: Select all
array('main1' => array('sub1'), 'main2' => array('sub2', 'sub3'));