// Funtion for displaying list.
// Receives one argument: an array.
function make_list ($parent) {
// Need the main pages array:
global $links;
// Start an unordered list:
echo '<ul class="sf-menu sf-vertical">';
// Loop through each subarray:
foreach ($parent as $pid => $nav_name) {
// Display the list item:
echo "<li class=\"sfHover\"><a href=\"$link_name\">$nav_name</a>";
// Check for subpages:
if (isset($links[$pid])) {
// Call this function:
make_list($links[$pid]);
}
// Complete the list item:
echo '</li>';
} // End of FOREACH loop.
// Close the unordered list:
echo '</ul>';
} // end of make_list() function
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Test nested navigation</title>
</head>
<body>
<?php
// Initialize the storage array:
$links = array();
while (list($page_id, $pid, $nav_name, $link_name ) = mysql_fetch_array($pageList, MYSQL_NUM)) {
// Add to the array:
$links[$pid][$page_id] = $nav_name;
}
// For debugging:
echo '<pre>' . print_r($links,1) . '</pre>';
// Send the first array element
// to the make_list() function:
make_list($links[$start]);
As you can see, I've added $link_name to the while(list()) but I can't understand how to get $link_name added to the array which contains the nested navigation items. You can also see how I have added $link_name to the <a> element in the <li> but when I test the script I only get <a href="">whatever</a>.
Here is my SQL:
mysql_select_db($database_siteuser, $siteuser); $query_pageList = "SELECT page_id, pid, nav_name, link_name, ordr FROM webtext WHERE page_id != 0 AND navInclude = 'y' OR sidebar_disp = 'y' ORDER BY pid, ordr"; $pageList = mysql_query($query_pageList, $siteuser) or die(mysql_error()); $row_pageList = mysql_fetch_assoc($pageList);
Any help would be appreciated.











