. I wish to travel a 2 column hierachy and prnt out the following javascript according to what is in the db.
var dogs = new Array("poodle","puli","greyhound");
where var dogs is the parent and poodle, puli, greyhound are the children.
mysql table looks like this
parent title
dogs
dogs poodle
dogs puli
dogs greyhound.
I can print out most of itb using this code. but I cannot close the javascript function beacuse I cant detect the end of the array returned.
function display_children($parent, $level){
// retrieve all children of $parent
$result2 = mysql_query('SELECT title, cat_id, parent from business_categories_hierachy WHERE parent ="'.$parent.'";');
$result2array = mysql_fetch_array($result2);
//echo($result2array);
$comma_separated = explode(",", '$result2array');
while ($row = mysql_fetch_array($result2)){
$cat_id= $row['cat_id'];
$cat_parent= $row['parent'];
//echo "$cat_parent ";
// indent and display the title of this child
if (!$cat_parent) {echo"test";
echo str_repeat('',$level). "var ".$row['title']."= new Array(";
} else {
echo str_repeat('',$level). "\"".$row['title']."\",";
}
// call this function again to display child children
display_children($row['title'], $level+1);
}
}
display_children('',0);