I inherited a website here at work. The menu system uses a convoluted jquery / javascript structure. There are 8 different types of "users" for this website, from administrator to contractor or accountant, etc, and the person made 8 different versions of the menus covering nearly 80 different pages within the site.
We have had success before on generating a menu with some jquery within a sharepoint site that had a "list" of the menu structure we needed, but I am having trouble translating to php and sql.
I have gotten the code to where if the user is an administrator, it pulls the correct menu items from the list. For now I am just viewing them in a table to verify they are the correct links.
Now I need to build the standard Unordered list html. I'm thinking this may be solved with some recursive programming, but I have very little experience using it.
The list im using to create my array object has 3 columns. Display(Link text), Path(href), parent(parent page, if the link has one).
The output needed would be a standard html list, with verying levels of "depth".
example:
<ul>
<li>Parent Page 1
<ul>
<li>child page 1a</1>
</ul>
</li>
<li>Parent Page 2</li>
<li>Parent Page 3
<ul>
<li>child page 3a</1>
<li>child page 3b
<ul>
<li>grandchild page 3a</1>
<li>grandchild page 3b</1>
</ul>
</1i>
</ul>
</li>
<li>Parent Page 4</li>
</ul>
My code below will grab the first parent pages, I'm just very unsure on where to take it from here.
$SQL = "SELECT * from menu_items";
$menu_items = pg_query( $cnx, $SQL);
if ($access == "admin") {
$SQL="SELECT * from menu_structure where roleid = '1'";
$result= pg_query( $cnx, $SQL);
$SQL = "SELECT * from menu_structure where roleid = '1'";
if (pg_num_rows($result) > 0) { // if query returns one or more rows worth of results
echo "
<ul>
";
for($i=0; $i<pg_num_rows($result); $i++){
$data = pg_fetch_array($result,$i);
for($j=0; $j<pg_num_rows($menu_items); $j++){
$item = pg_fetch_array($menu_items,$j);
if($data["itemid"] == $item["id"]){
if($item["parent"] == null){
echo "<li>";
echo "<a href='".$item["path"]."'>".$item["display"]."</a>";
echo "</li>";
}
}
}
}
echo "</ul>";
}
}
I have 2 postgres tables. One is the list i illustrated above, with each Link, href, and parent page defined. The second table is the relation of each "user" type to what items will be made availabe in the navigation.
Anyone?