Hi I am using a 2 column mysql table to represent a parent child hierachy . columns are parent, child,
I wish to create arrays named after each of the parent element containing the names of all child elements.
I have created an initial array call main array to hold the parent arrays, but I cannot think of a way to create the child arrays and fill them.
parent child
fish trout
fish mackeral
dog terrier
dog bulldog
dog
fish
<?php
function Recursive_call ($parent, $level) {
$main array = array();
while ($row= mysql_fetch_array($result_test) ){
$cat_parent = $row ['parent'];
$cat_child = $row ['child'];
}
// find parent catgories
if (!$cat_parent){
array_push ($main_array, $cat_title);
}
// for all other catgories
if ($cat_parent && $cat_child)
{
array_push ($cat_parent, $cat_child)
}
Recursive_call ($row['child'], $level+1);
}
// call function
Recursive_call ('', 0);