Dynamic menu privilege not working

Here is my Code

<ul class="nav side-menu">


              <?php 
            $mnquery=$ob->showDataall("select * from menus where parent_id='0' and delet='0'");
            foreach($mnquery as $value)
                {
                    $selquery=$ob->showDataall("select * from menu_permission where staff_id='".$_SESSION['user_id']."'");
                    foreach($selquery as $nquery)
                        {
                            foreach(explode(",",$nquery['permission']) as $mnu)
                                {
                                    if($value['menu_id']==$mnu)
                                        {
                                    ?>
        <li><a <?php if($value['menu_hyper']!='#'){ echo 'href="'.$value['menu_hyper'].'"';}?>><i class="fa fa-bars"></i><?php echo $value['menu_name']; if($value['menu_hyper']=='#'){?><span class="fa fa-chevron-down"></span><?php }?></a>
                                    <?php
                                        $submnquery=$ob->showDataall("select * from menus where parent_id='".$mnu."' and delet='0'");
                                        if(!empty($submnquery))
                                        foreach($submnquery as $subvalue)
                                            {
                                                if($subvalue['parent_id']==$mnu)
                                                    {
                                    ?>
                                                    <ul class="nav child_menu" style="display: none">
                                                        <li><a <?php if($subvalue['menu_hyper']!='#'){ echo 'href="'.$subvalue['menu_hyper'].'"';}?>><?php echo $subvalue['menu_name']; if($subvalue['menu_hyper']=='#'){?><span class="fa fa-chevron-down"></span><?php }?></a>
                                                        <?php
                                                            $chldmnquery=$ob->showDataall("select * from menus where parent_id='".$subvalue['menu_id']."' and delet='0'");
                                                            if(!empty($chldmnquery))
                                                            foreach($chldmnquery as $chldvalue)
                                                                {
                                                                    if($chldvalue['parent_id']==$subvalue['menu_id'])
                                                                    {
                                                        ?>
                                                            <ul class="nav child_menu" style="display: none">
                                                                <li><a href="<?php echo $chldvalue['menu_hyper'];?>"><?php echo $chldvalue['menu_name'];?></a></li>
                                                            </ul>
                                                        <?php
                                                                    }
                                                                }
                                                        ?>

                                                        </li>
                                                    </ul>
                                <?php
                                                    }
                                            }
                                ?>
                                    </li>
                                <?php
                                        }
                                }
                        }
                }
              ?>
</ul>

Here is my function showDataall

public function showDataall($result) 
    {
        $q = $this->conn->prepare($result) or die("failed!");
        $q->execute();
        while ($r = $q->fetch(PDO::FETCH_ASSOC)) 
        {
            $data[] = $r;
        }
        return $data;
    }

Here is my Table named 'menus'

     menu_id       menu_name            menu_hyper                 parent_id    delet
        1         Master Settings            #                         0         0
        2         Add New Menu       ../pages/menu_add.php             1         0
        3         Menu Permission    ../pages/menu_permissions.php     1         0
        4         Role               ../pages/add_role.php             1         0
        5         Staff              ../pages/add_staff.php            1         0
        6         Add Product        ../pages/product_add.php          0         0

Here is my Other table named 'menu_permission'

  id    staff_id    permission
   1       1        1,2,3,4,5,6
   2       2        1,4

I allow all menu privilege for 'staff_id=1' I allow menu_id 1 and 4 for 'staff_id=2' staff_id=1 is logged in all menus shown but staff_id=2 is logged in all menus are shown I allow only two menus for staff_id=2 (menu_id = 1 and menu_id = 2) how to solve this problem

Please help me....

Answers


I write on my Knowledge ... Its Work Perfectly any one help me to simplify this code

              <?php 
            $mnquery=$ob->showDataall("select * from menus where parent_id='0' and delet='0'");
            foreach($mnquery as $value)
                {
                    $selquery=$ob->showDataall("select * from menu_permission where staff_id='".$_SESSION['user_id']."'");
                    foreach($selquery as $nquery)
                        {
                            foreach(explode(",",$nquery['permission']) as $mnu)
                                {
                                    if($value['menu_id']==$mnu)
                                        {
                                    ?>
        <li><a <?php if($value['menu_hyper']!='#'){ echo 'href="'.$value['menu_hyper'].'"';}?>><i class="fa fa-bars"></i><?php echo $value['menu_name']; if($value['menu_hyper']=='#'){?><span class="fa fa-chevron-down"></span><?php }?></a>
                                    <?php
                                        $submnquery=$ob->showDataall("select * from menus where parent_id='".$mnu."' and parent_id!='0' and delet='0'");
                                        if(!empty($submnquery))
                                        foreach($submnquery as $subvalue)
                                            {
                                                $selquery=$ob->showDataall("select * from menu_permission where staff_id='".$_SESSION['user_id']."'");
                                                foreach($selquery as $nquery)
                                                    {
                                                        foreach(explode(",",$nquery['permission']) as $mnua)
                                                            {
                                                if($subvalue['menu_id']==$mnua)
                                                    {
                                    ?>
                                                    <ul class="nav child_menu" style="display: none">
                                                        <li><a <?php if($subvalue['menu_hyper']!='#'){ echo 'href="'.$subvalue['menu_hyper'].'"';}?>><?php echo $subvalue['menu_name']; if($subvalue['menu_hyper']=='#'){?><span class="fa fa-chevron-down"></span><?php }?></a>





                                                  <?php
                                                            $chldmnquery=$ob->showDataall("select * from menus where parent_id='".$subvalue['menu_id']."' and delet='0'");
                                                            if(!empty($chldmnquery))
                                                            foreach($chldmnquery as $chldvalue)
                                                                {
                                                                    $selquery=$ob->showDataall("select * from menu_permission where staff_id='".$_SESSION['user_id']."'");
                                                foreach($selquery as $nquery)
                                                    {
                                                        foreach(explode(",",$nquery['permission']) as $mnub)
                                                            {
                                                                    if($chldvalue['menu_id']==$mnub)
                                                                    {
                                                        ?>
                                                            <ul class="nav child_menu" style="display: none">
                                                                <li><a href="<?php echo $chldvalue['menu_hyper'];?>"><?php echo $chldvalue['menu_name'];?></a></li>
                                                            </ul>
                                                        <?php
                                                                    }
                                                                }
                                                    }
                                                                }
                                                        ?>      

                                                        </li>
                                                    </ul>
                                <?php
                                                    }
                                            }
                        }
                                            }
                                ?>
                                    </li>
                                <?php
                                        }
                                }
                        }
                }
              ?>
</ul>

Try to change this part:

foreach(explode(",",$nquery['permission']) as $mnu)

to:

$mypermission = explode(",",$nquery['permission']);

and then

foreach($mypermission as $mnu)

Need Your Help

Russian puppets displayproblem with Firefox and Webkit: works well with IE

javascript firefox button webkit

I have a teaching web page where, in a particular section (DIV), a series of Questions must appear one after another. Once the user answer Q1, then Q2 is shown just below, etc.