name : table_home.php
<div id="error_del_client"></div>
<div class="table-responsive">
<table class="table table-bordered table-striped table-hover"  style="background-color:white;" id="table_direc">
    <thead>
      <tr>
        <th>#</th>
        <th>Home Image</th>
        <th>Edit</th>
        <th>Delete</th>
      </tr>
    </thead>
    <tbody>
        <?php 
            include('../config/config.php');
            $sql = "SELECT * FROM homes ";
            $res = $conn->query($sql);
            $n = 0;
            while($row = $res->fetch_assoc()){
        ?> 
        <tr>
           <td width="5%"><?php echo ++$n; ?></td>
           <td width="20%"><?php echo '<img src="'."../".$row['h_image'].'" width="100%" class="img-responsive"/>' ?></td>
           <td width="5%"><a href="edit_home.php?q=<?php echo $row['h_id']; ?>" class="btn btn-success edit_home" atr="">Edit</a></td>
           <td width="5%"><button class="btn btn-danger del_home" atr="<?php echo $row['h_id']; ?>">Delete</button></td>
         </tr>
          
          <?php 
          }
          ?>
    </tbody>
  </table>
  </div>
<script src="dist/js/jquery.validate.min.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
  <script>
  $(function () {
    $('#table_direc').DataTable({
      'paging'      : true,
      'lengthChange': true,
      'searching'   : true,
      'ordering'    : true,
      'info'        : true,
      'autoWidth'   : true
    })
  })
  

  $(".del_home").click(function(){
    var q =  $(this).attr("atr");
   if(confirm('Warning confirm delete Home Image  !!!  ')){
      $.ajax({
        url:"del_home.php",
        type:"post",
        data:{q:q},
      }).done(function(data){
        if(data == 1){
          $("#error_del_client").html('<div class="alert alert-danger">Delete Home complete</div>').delay(5000).fadeOut(function(){  $("#table_home").load('table_home.php'); });
        }else{
          console.log(data);
          return false;
        }
      });
  }else{
    console.log(data);
          return false;
  }
});
</script>


© 2024 UnknownSec