I am trying to populate a multidimensional array with a simple (categories > sub_categories) I get the categories into the array just fine but I can't figure out how to populate the sub_categories as array belonging to the first categories array; I am close.. here is the code. (the problem is about 7 lines from the bottom $cat[$i][$i2] = $subcat😉
// get top categories from database
$query = "select tc.top_category_name from top_categories tc order by top_category_name";
$result = mysql_query($query);
$numberOfRows = mysql_num_rows($result);
$i = 0;
$cat = array(); // define the array
if ($numberOfRows>0)
{
while ($i<$numberOfRows)
{
$topcat = mysql_result($result,$i,"top_category_name");
// poulate array with first element 'top category'
$cat[$i] = $topcat;
// get subcategories from database
$query ="select c.category_name from categories c
left join cat2top_cat c2t on c2t.category_id = c.category_id
left join top_categories tc on tc.top_category_id = c2t.top_category_id
where tc.top_category_name = '".$topcat."'";
$resultsub = mysql_query($query);
$numberOfRows2 = mysql_num_rows($resultsub);
$i2 = 0;
while ($i2<$numberOfRows2)
{
$subcat = mysql_result($resultsub,$i2,"category_name");
// I need to add each subcategory to array here.
echo "<br>".$topcat."-".$i2.$subcat."<br>";
/*********************************************/
// this part is not working
$cat[$i][$i2] = $subcat;
/**********************************************/
$i2++;
}
$i++;
}
}
Any help is appreciated