Hi all
I have a table with thousands of rows of data. Each row has many columns, two of which are:
Category
Sub-category
What I need to do is create an array in a PHP loop which associates all unique Sub-category strings to the unique Category strings from my table.
An example of the table data (Category / Sub-Category) would be as follows:
Apparel | Shoes
Apparel | trousers
Jewellery | Watches
Jewellery | Rings
Furniture | Chairs
Therefore my output array needs to be as follows:
array {
'Apparel' => array('Shoes','trousers'),
'Jewellery' => array('Watches','Rings'),
'Furniture' => array('Chairs')
}
How can I do this in PHP?
Here is my starting code:
$qry = "SELECT category, sub-category FROM tblproducts";
$res = mysql_query($qry);