Page 1 of 1

Category arranging

Posted: Tue Aug 21, 2007 9:31 pm
by HiddenS3crets
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

Code: Select all

main1   |   main2
--------------------
sub1    |   sub2
        |   sub3
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

Code: Select all

array('main1' => array('sub1'), 'main2' => array('sub2', 'sub3'));

Posted: Tue Aug 21, 2007 11:35 pm
by feyd
Read the first two threads linked from Useful Posts.

Posted: Wed Aug 22, 2007 4:21 am
by CoderGoblin
Just so you realise if not immediately obvious to you. Feyd is being nice as the link to Useful Posts is in his signature.