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?

Recommended Answers

All 2 Replies

Member Avatar for LastMitch

@bleedsgreen33

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.

I think it's bit too much for anyone to do. I think you need to pay someone to do this.

Maybe 2 users or the max 3 users but 8 users menu? That's too much work to ask.

this is how i accomplished the same aspect for handling auth page users.

<?php
function logged_in_redirect()
{
    if(user_page()=== 1)
    {
        header('Location: customer/index.php');
    }
    elseif(user_page() ===2)
    {
        header('Location:customer/index.php');
    }
    elseif (user_page() ===3)
    {
        header('Location:contractor/index.php');
    }
    elseif(user_page() ===4)
    {
        header('Location:contractor/index.php');
    }
    elseif(user_page() ===5)
    {
        header('Location:architect/index.php');
    }
    elseif(user_page() ===6)
    {
        header('Location:architect/index.php');
    }
    elseif(user_page() ===7)
    {
        header('Location:indextemp.php');
    }
    exit(); 
}



function user_page(){
    $sql=mysql_query("SELECT idtype_of_contact FROM `contact`  WHERE contact_id=".$_SESSION['contact_id']);
    $num_rows = mysql_num_rows($sql);
    if($num_rows ==0){}
    while($row=mysql_fetch_array($sql)){
        $page=$row["idtype_of_contact"];
        return $page;
    }
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.