johnnyb
09-24-2004, 06:09 AM
Hi,
I've made this function to create my menu and it works great except for one thing - I need the $opener variable to be set before it is, and I can't really switch it around.
I think it is possible to do what I want by replacing the echo statements by a string variable which appends to itself, but I haven't been able to make that work properly - mostly because I'm not that great working with functions and variable scope.
So, here's the code:
function make_menu( $level,$CNX,$page ){
$theString = NULL;
$opener = NULL;
$toPrint = NULL;
$after = NULL;
$subjectQuery = "SELECT page.PAGE_TITLE, page.PAGE_ID, page.PAGE_FILE_NAME, page.NEXT_PAGE, page.PARENT_PAGE FROM page WHERE PARENT_PAGE = ".$level." ORDER BY PAGE_TITLE";
$subjectResult = mysql_query($subjectQuery,$CNX) or die(mysql_error());
while($subjectRow = mysql_fetch_assoc($subjectResult)){
//check if there are children
$checkQuery = "SELECT page.PAGE_TITLE, page.PAGE_ID, page.PAGE_FILE_NAME, page.NEXT_PAGE, page.PARENT_PAGE FROM page WHERE PARENT_PAGE = ".$subjectRow["PAGE_ID"]." ORDER BY PAGE_TITLE";
$checkResult = mysql_query($checkQuery,$CNX) or die(mysql_error());
if( mysql_num_rows($checkResult) > 0 ){
//make_opener($level,$CNX,$page,&$opener);
echo '<li class="';
echo $opener; // this is where I need to have the variable already set
echo '"><a href="#" class="icon" onclick="return door(this);"></a>'.'<a href="'.$subjectRow["PAGE_FILE_NAME"].'" class="parent">'.$subjectRow["PAGE_TITLE"]."</a>\n";
echo '<ul class="item">'."\n";
make_menu($subjectRow["PAGE_ID"], $CNX, $page, &$opener);
} else {
// $opener shoule be set in this if...else statement
if ($subjectRow["PAGE_ID"] == $page) {
echo '<li><a href="'.$subjectRow["PAGE_FILE_NAME"].'" class="parent">'.$subjectRow["PAGE_TITLE"]."</a>";
} else {
echo '<li><a href="'.$subjectRow["PAGE_FILE_NAME"].'">'.$subjectRow["PAGE_TITLE"]."</a>";
}
}
echo "</li>"."\n";
//reset child checking query and result to nothing
mysql_free_result($checkResult);
$checkQuery = NULL;
} // end the while loop
echo "</ul>\n";
//echo $theString;
$theString = NULL;
return ;
mysql_free_result($subjectResult);
} // end make_menu function
function menu_maker($level,$CNX,$page) {
echo '<ul id="menuTree">'."\n";
if ($page == 53) {
echo '<li class="announceheading">Encyclopedia:</li>'."\n";
} elseif ($page == 10) {
echo '<li class="announceheading">Studio to Stage:</li>'."\n";
}
$theString=NULL;
make_menu($level,$CNX,$page);
} // end menu_maker function
I've made this function to create my menu and it works great except for one thing - I need the $opener variable to be set before it is, and I can't really switch it around.
I think it is possible to do what I want by replacing the echo statements by a string variable which appends to itself, but I haven't been able to make that work properly - mostly because I'm not that great working with functions and variable scope.
So, here's the code:
function make_menu( $level,$CNX,$page ){
$theString = NULL;
$opener = NULL;
$toPrint = NULL;
$after = NULL;
$subjectQuery = "SELECT page.PAGE_TITLE, page.PAGE_ID, page.PAGE_FILE_NAME, page.NEXT_PAGE, page.PARENT_PAGE FROM page WHERE PARENT_PAGE = ".$level." ORDER BY PAGE_TITLE";
$subjectResult = mysql_query($subjectQuery,$CNX) or die(mysql_error());
while($subjectRow = mysql_fetch_assoc($subjectResult)){
//check if there are children
$checkQuery = "SELECT page.PAGE_TITLE, page.PAGE_ID, page.PAGE_FILE_NAME, page.NEXT_PAGE, page.PARENT_PAGE FROM page WHERE PARENT_PAGE = ".$subjectRow["PAGE_ID"]." ORDER BY PAGE_TITLE";
$checkResult = mysql_query($checkQuery,$CNX) or die(mysql_error());
if( mysql_num_rows($checkResult) > 0 ){
//make_opener($level,$CNX,$page,&$opener);
echo '<li class="';
echo $opener; // this is where I need to have the variable already set
echo '"><a href="#" class="icon" onclick="return door(this);"></a>'.'<a href="'.$subjectRow["PAGE_FILE_NAME"].'" class="parent">'.$subjectRow["PAGE_TITLE"]."</a>\n";
echo '<ul class="item">'."\n";
make_menu($subjectRow["PAGE_ID"], $CNX, $page, &$opener);
} else {
// $opener shoule be set in this if...else statement
if ($subjectRow["PAGE_ID"] == $page) {
echo '<li><a href="'.$subjectRow["PAGE_FILE_NAME"].'" class="parent">'.$subjectRow["PAGE_TITLE"]."</a>";
} else {
echo '<li><a href="'.$subjectRow["PAGE_FILE_NAME"].'">'.$subjectRow["PAGE_TITLE"]."</a>";
}
}
echo "</li>"."\n";
//reset child checking query and result to nothing
mysql_free_result($checkResult);
$checkQuery = NULL;
} // end the while loop
echo "</ul>\n";
//echo $theString;
$theString = NULL;
return ;
mysql_free_result($subjectResult);
} // end make_menu function
function menu_maker($level,$CNX,$page) {
echo '<ul id="menuTree">'."\n";
if ($page == 53) {
echo '<li class="announceheading">Encyclopedia:</li>'."\n";
} elseif ($page == 10) {
echo '<li class="announceheading">Studio to Stage:</li>'."\n";
}
$theString=NULL;
make_menu($level,$CNX,$page);
} // end menu_maker function