PHP Variable variable with mysql

Alright, so I am trying to create a dynamic PHP navigator, populating the the navigator tabs from a database table ‘pages’. I have the parent tabs working properly except I am having difficulty with the sub items under the parent category.

Example
101, 0, Home, ./
102, 0, Services, services.php
103, 0, About, about.php
104, 102, Carpentry, (file name of parent element)?catid=[this id]
105, 0, Contact Us, contact.php

Navigator Output

Home Services About Carpentry Contact Us

I want to get the sub elements, say Carpentry, under the proper parent id, Services, and not have them all displayed in the main nav.

Code:

[php]
$query = “select * from pages”;
if(!$result=mysql_query($query, $con)) {
$estr = mysql_error();
mysql_close($con);
error($estr);
}
$nav = array();
while($arr = mysql_fetch_array($result)) {
if($arr[‘pub’] != 0) { //Published or not

	if($arr['sub_id'] == $arr['id']) { //If sub equals to parent id, put under parent
		${$arr['id']} = array(); //trying to assign variables dynamically
		echo "${$arr['id']}";
		$pgtu = $arr['pgFileName']; //primary page name to use
		${$arr['id']}['title'] = "".$pgtu."?catid=".$arr['id']."";
		$nav[$arr['title']] = array($arr['pgFileName'], ${$arr['id']}); //sub items
	}
	$nav[$arr['title']] = array($arr['pgFileName']); //This takes the name of the page, and the file name and just puts them together nicely
}

}
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service