 <?php 
 include'config.php'; 
 $user='test-ADMIN';
 $desi='ADMIN';
 // $fnid = array();
 // $version = array();
 $querry="Select * from tbl_features where parent ='0' group by fnid order by id";
 $result =  mysqli_query($con, $querry);
 while($row = mysqli_fetch_array($result)) 
 {
    $querry2="Select * from tbl_permission where user='".$user."' and desi='".$desi."' ";
    $result2 =  mysqli_query($con, $querry2);
    while($row2= mysqli_fetch_array($result2)) 
    {
      $test= substr($row2[$row['fnid']], 0,1);
      $fetch[] = array($row['fnid']=>$test,"fnid"=>$row['fnid']);
  }
}
foreach($fetch as $index => $data)
{
    $version[$data['fnid']]=$data[$data['fnid']];
    // $fnid[count($fetch)]=$data['fnid'];
}
print_r($version);
// for($i=0;$i<count($fetch);$i++)
// {
$querry="Select * from tbl_features where parent = '0' group by fnid order by id";
$result =  mysqli_query($con, $querry);
while($row = mysqli_fetch_array($result)) 
{
    if ($version[$row['fnid']]=='0') {
        $querry3="Select * from tbl_features where fnid='".$row['fnid']."' ";
        // $querry3="Select * from tbl_features where fnid='".$row['fnid']."' and version ='".$version[$row['fnid']]."'";
        $result3 =  mysqli_query($con, $querry3);
        while($row3 = mysqli_fetch_array($result3)) 
        {
          echo "<li class='treeview'>";
          if ($row3['parent']=="0") {
              $name='href="#"';
          } 
          else {
              $name='class="profile" href="#"';
              // $name='class="profile" href="'.$row3['file_name'].'"';
          }
          ?>
          <a <?php print_r($name);?> ><i class="<?php echo $row3['icon'] ;?>"  ></i><span title="<?php echo $row3['disc'];?>"><?php echo $row3['fname'] ;?></span>
            <?php
            if(isset($row3['level'])){
                if($row3['level']==0){
                   echo '<span class="pull-right-container">
                   <i class="fa fa-angle-left pull-right"></i>
                   </span>';
               }
               else if ($row3['level']==1) {
               
   }
   ?></a>
</li>
<?php
}
}
}
}
?>