<script>
  function del(iden,action){
    var dataString = "id="+iden+"&action="+action;
    var status = $("#status").val();
    var identity = $('#loading')+iden;
    var confirms = confirm("Clicking this will delete this person, are you sure you want to continue?");
    if (confirms == true) {
    $.ajax({
        type: "POST",
        url: "control.php",
        cache : false,
        data : dataString,
        beforeSend : function(){
            $('#del'+iden).hide();
            $('#loading'+iden).show();
        },
        success : function(response){
            $('#loading'+iden).hide();
            document.getElementById('inputHere').innerHTML = response;
            $('#myModal').modal('show');
            window.location.reload(1);
        }
    });
}
}


function refr(iden,action){
    var dataString = "id="+iden+"&action="+action;
    var status = $("#status").val();
    var identity = $('#loading')+iden;
    var confirms = confirm("Clicking this will refresh password, are you sure you want to continue?");
    if (confirms == true) {
    $.ajax({
        type: "POST",
        url: "control.php",
        cache : false,
        data : dataString,
        beforeSend : function(){
            $('#refr'+iden).hide();
            $('#refre'+iden).show();
        },
        success : function(response){
            $('#refre'+iden).hide();
            document.getElementById('inputHere').innerHTML = response;
            $('#myModal').modal('show');
        }
    });
}
}
</script>

                  <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
              <div class="title_left">
                <h3><a href="main.php">Dashboard</a>/<a href=" ">View Student</a></h3>
              </div>
            </div>

            <div class="clearfix"></div>

            <div class="row">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>View Student</h2>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                      <table id="datatable-responsive" class="table table-striped table-bordered" cellspacing="0" width="100%">
                            <thead>
                             <tr>
                                <th>S/N</th>
                                <th>Name</th>
                                <th>Matric</th>
                                <th>Department</th>
                              </tr>
                            </thead>
                            <tbody>
                        <?php
                         $select = $conn->query("SELECT * FROM students");
                            $fetch = $select->fetchAll(PDO::FETCH_OBJ);
                            $count = $select->rowCount();
                            $serial = 1;
                            if ($count > 0) {
                              foreach ($fetch as $value) {
                                $iden = $value->id;
                                $sname = $value->sname;
                                $oname = $value->oname;
                                $matric = $value->matric;
                                $dept = $value->dept;
                                $name = "$sname $oname";
                            ?>
                              <tr>
                                <td><?php echo $serial; ?></td>
                                <td><?php echo $name; ?></td>
                                <td><?php echo $matric; ?></td>
                                <td>
                                  <?php
                                    $select2 = $conn->query("SELECT * FROM department WHERE id = '$dept' ");
                                  $fetch2 = $select2->fetchAll(PDO::FETCH_OBJ);
                                  $count2 = $select2->rowCount();
                                  if ($count2 > 0) {
                                    foreach ($fetch2 as $value2) {
                                      $name2 = $value2->name;
                                      echo "$name2";
                                    }
                                  } 

                                    
                                  ?>
                                  </td>
                              </tr>
                              
                            <?php
                            $serial++;
                              }
                            }
                        ?>
                            </tbody>
                          </table>
                            </div>
                            </div>
              </div>
            </div>
          </div>
        </div>
        <!-- /page content -->


<div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog modal-sm">
      <div class="modal-content">
        <div class="modal-body text-center">
        <div id="inputHere">

        </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Ok</button>
        </div>
        </div>
        </div>
      </div>
    </div>


<div class="modal fade" id="myModal2" role="dialog">
    <div class="modal-dialog modal-sm">
      <div class="modal-content">
        <div class="modal-body text-center">
        <?php  
        if (isset($mess)) {
        echo "$mess";
        }
        ?>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Ok</button>
        </div>
      </div>
    </div>
  </div>

<?php
if(isset($mess)){
?>
<script type="text/javascript">
   $(window).load(function(){
   $('#myModal2').modal('show');
   }); 
</script>
<?php
  }
?>