rendered paste body<pre style="text-align:left">
<?php
#Our built up categories, stored throughout the store session.
$catCache = array();
#Replace with a query to pull out the cats, this is just a hard-coded array of what it should pull if we did a select * currently.
$fetch = array( 1 => array( 'group_id' => 1,
'group_title' => 'Skins',
'group_description' => '',
'use_addons' => 1,
'hide' => 0,
'parent' => 0
),
99 => array( 'group_id' => 99,
'group_title' => 'Add-Ons',
'group_description' => 'Purchase a custom logo or color for the skin you\'re buying!',
'use_addons' => 0,
'hide' => 1,
'parent' => 0
),
101 => array( 'group_id' => 101,
'group_title' => 'Dark Skins',
'group_description' => 'Skins with a dark tone.',
'use_addons' => 1,
'hide' => 0,
'parent' => 1
),
102 => array( 'group_id' => 102,
'group_title' => 'Light Skins',
'group_description' => 'Skins with a light tone.',
'use_addons' => 1,
'hide' => 0,
'parent' => 1
) );
#Run through and pull out root level cats, and their sub-categories.
foreach( $fetch as $dbRow )
{
#Is it a parent and shown?
if( $dbRow['parent'] == 0 and $dbRow['hide'] == 0 )
{
$catCache[ $dbRow['group_id'] ] = array( 'id' => $dbRow['group_id'],
'title' => $dbRow['group_title'],
'desc' => $dbRow['group_description'],
'addon' => $dbRow['use_addons']
);
}
#Is this a child category that isn't hidden?
if( $dbRow['parent'] !== 0 and $dbRow['hide'] == 0 )
{
$catCache[ $dbRow['parent'] ]['subs'][] = array( 'id' => $dbRow['group_id'],
'title' => $dbRow['group_title'],
'desc' => $dbRow['group_description'],
'addon' => $dbRow['use_addons']
);
}
}
print_r( $catCache );
?>
</pre>