<!-- <form method="post" id="insert_form1">   -->
  <div class="box-body">
   <div class="col-md-12">
    <div class="nav-tabs-custom">
      <ul class="nav nav-tabs">
        <?php
        include('config.php');
        $sql = "SELECT * FROM tbl_features Where fnid ='".$_POST['id']."'";
        $result = mysqli_query($con, $sql);
        $i=0;
        if (mysqli_num_rows($result) > 0) {
         while($row = mysqli_fetch_assoc($result)) {
           $i++;
           if ($row['version']=='1'||$row['version']=='0') {
             $class='active';
           }
           else{
            $class='';
          }
          ?>
          <li class="<?php echo $class;?>"><a href="#Version<?php echo $i;?>" data-toggle="tab">Version - <?php echo $i;?></a></li>                  
          <?php   
        } 
        ?>
        <li><a href="#Version<?php echo $i+1;?>" data-toggle="tab">Add New Version - <?php echo $i+1;?></a></li>                  

      </ul>
      <div class="tab-content">
        <?php 
        $sql = "SELECT * FROM tbl_features Where fnid ='".$_POST['id']."'";
        $result = mysqli_query($con, $sql);
        $i=0; 
        while($row = mysqli_fetch_assoc($result)) {
         $i++;
         if ($row['version']=='1') {
           $class='active ';
         }
         else{
          $class='';
        }
        ?>
        <div class="<?php echo $class;?> tab-pane" id="Version<?php echo $i;?>">
          <form method="post" name='UpdateData'>  
            <div class="row">
              <div class="col-md-6">
                <div class="form-group">
                  <label for="cuname">Parent
                  </label>
                  <select class="form-control" id="parent" name="parent" placeholder="Enter Parent">
                    <?php
                    $sql1 = "SELECT * FROM tbl_features Where id='".$row['parent']."'";
                    $result1 = mysqli_query($con, $sql1);
                    if (mysqli_num_rows($result1) > 0) {
                      while($row1 = mysqli_fetch_assoc($result1)) {
                       ?>
                       <option value="<?php echo $row1['id'];?>" selected><?php echo $row1['fname'];?></option>
                       <?php             
                     }
                   }else{ 
                    echo 0;

                    ?>
                    <option value="0">Parent</option>
                  <?php }?>
                  <?php
                  include('config.php');
                  $sql1 = "SELECT * FROM tbl_features Where id!='".$row2['parent']."'";
                  $result1 = mysqli_query($con, $sql1);
                  if (mysqli_num_rows($result1) > 0) {
                    while($row1 = mysqli_fetch_assoc($result1)) {
                     ?>
                     <option value="<?php echo $row1['id'];?>"><?php echo $row1['fnid'].' - '.$row1['fname'];?></option>
                     <?php             
                   }
                 } 
                 ?> 
               </select>
             </div>
             <div class="form-group">
              <label for="cuname">Function id
              </label>
              <input type="text" class="form-control" id="fnid" readonly name="fnid" value="<?php echo $row['fnid'];?>" placeholder="Enter Username" >
            </div>
            <div class="form-group">
              <label for="ccontact">Function Name
              </label>
              <input type="text" class="form-control" id="fname" name="fname" value="<?php echo $row['fname'];?>" placeholder="Enter Function Name">
            </div>
            <div class="form-group">
              <label for="c_name">Discription
              </label>
              <input type="text" class="form-control" id="disc" name="disc" value="<?php echo $row['disc'];?>"  placeholder="Enter Discription">
            </div>
          </div>
          <div class="col-md-6">
            <div class="form-group">
              <label for="cpass">File Name
              </label>

              <input type="text" class="form-control" id="file_name" name="file_name" value="<?php echo $row['file_name'];?>" placeholder="File Name" >

            </div>
            <div class="form-group">
              <input type="hidden" class="form-control" id="date" name="date" value="<?php echo $row['date'];?>" placeholder="Enter Registred Date">
            </div>
            <div class="form-group">
              <label for="c_name">Icon
              </label>
              <input type="text" class="form-control" id="icon" name="icon" value="<?php echo $row['icon'];?>" placeholder="Enter icon">
            </div>
            <div class="form-group">
              <label for="c_name">Version
              </label>
              <input type="text" class="form-control" id="version" readonly name="version" value="<?php echo $row['version'];?>" placeholder="Enter Version">
            </div>
            <div class="form-group">
              <label for="c_name">Prefrence
              </label>
              <input type="number" class="form-control" id="forder" name="forder" value="<?php echo $row['forder'];?>" placeholder="Enter Prefrence">
            </div>
          </div>
        </div>
        <input type="hidden" name="request_type" id="request_type" value="1" />  
        <input type="hidden" name="employee_id" value="<?php echo $row['id'];?>" id="employee_id" />  
        <input type="button" name="insert" id="btn_update" onclick="update_data();" value="Save" class="btn btn-success btn_update" />
      </form>
    </div>
    <?php
  }             
  ?>
  <div class="tab-pane" id="Version<?php echo $i+1;?>">
    <?php $sql2 = "SELECT * FROM tbl_features Where fnid ='".$_POST['id']."'";
    $result2 = mysqli_query($con, $sql2);
    $row2 = mysqli_fetch_assoc($result2);
    ?>
    <form method="post" name='AddData'>
      <div class="row">
        <div class="col-md-6">
          <div class="form-group">
            <label for="cuname">Parent
            </label>
            <select class="form-control" id="parent" name="parent"  placeholder="Enter Parent">
              <?php
              $sql1 = "SELECT * FROM tbl_features Where id='".$row2['parent']."'";
              $result1 = mysqli_query($con, $sql1);
              if (mysqli_num_rows($result1) > 0) {
                while($row1 = mysqli_fetch_assoc($result1)) {
                 ?>
                 <option value="<?php echo $row1['id'];?>"><?php echo $row1['fname'];?></option>
                 <?php             
               }
             }else{ 
              echo 0;

              ?>
              <option value="0">Parent</option>
            <?php }?>
          </select>
        </div>
        <div class="form-group">
          <label for="cuname">Function id
          </label>
          <input type="text" class="form-control" readonly id="fnid" name="fnid" readonly value="<?php echo $row2['fnid'];?>" placeholder="Enter Username" >
        </div>
        <div class="form-group">
          <label for="ccontact">Function Name
          </label>
          <input type="text" class="form-control" id="fname" readonly name="fname" value="<?php echo $row2['fname'];?>" placeholder="Enter Function Name">
        </div>
        <div class="form-group">
          <label for="c_name">Discription
          </label>
          <input type="text" class="form-control" id="disc" name="disc" value="<?php echo $row2['disc'];?>"  placeholder="Enter Discription">
        </div>
      </div>
      <div class="col-md-6">
        <div class="form-group">
          <label for="cpass">File Name
          </label>
          <!-- <?php $j= $i+1; $demo1= substr($row2['file_name'], 0,-5);  $demo2= $demo1.$j.".php"?> -->
          <?php $j= $i+1; $demo1=$row2['file_name'];  $demo2= $demo1.$j;?>
          <input type="text" class="form-control" id="file_name" name="file_name" value="<?php echo $demo2;?>" placeholder="File Name" >
        </div>
        <div class="form-group">
          <input type="hidden" class="form-control" id="date" name="date" value="<?php echo date("Y/m/d");?>" placeholder="Enter Registred Date">
        </div>
        <div class="form-group">
          <label for="c_name">Icon
          </label>
          <input type="text" class="form-control" id="icon" name="icon" value="<?php echo $row2['icon'];?>" placeholder="Enter icon">
        </div>
        <div class="form-group">
          <label for="c_name">Version
          </label>
          <input type="text" class="form-control" id="version" readonly name="version" value="<?php echo $row2['version']+$i;?>" placeholder="Enter Version">
        </div>
        <div class="form-group">
          <label for="c_name">Prefrence
          </label>
          <input type="number" class="form-control" id="forder" name="forder" readonly placeholder="Enter Version">
        </div>
      </div>
    </div> 
    <input type="hidden" name="request_type" id="request_type" value="1" />  
    <input type="hidden" name="employee_id" value="" id="employee_id" />  
    <input type="button" onclick="addnew_data();" value="Save" class="btn btn-success" />
  </form>
</div>
<?php   }
?>
</div>
</div>
</div>
</div> 