简体   繁体   中英

Reload table without refreshing whole page in php

I'm fetching data in a table from database, and there are three buttons update,delete and active/inactive button,, all three have their own functionalities, but after the event it has to reload the updated data in table. I'm able to reload whole page but i want to reload only the table content,, I have less knowledge about Javascript and ajax.. I'm not getting proper way to proceed with ajax.. Please help me with any procedure that can can solve my problem.. How correctly i can integrate in my code.

 <?php session_start(); if(empty($_SESSION)) { header("Location: ../vendor/login.php"); } $mpage = "printer"; $page = "list_printer.php"; include '../header.php'; ?> <!DOCTYPE html> <html> <!-- Content Wrapper. Contains page content --> <div class="content-wrapper"> <!-- Content Header (Page header) --> <section class="content-header"> <h1> Printer Lists </h1> <ol class="breadcrumb"> <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li> <li><a href="#">Printer</a></li> <li class="active">List Printers</li> </ol> </section> <!-- Main content --> <section class="content"> <div class="row"> <div class="col-xs-12"> <?php //echo session_id(); $email1 = $_SESSION['email']; $Vendor_id="SELECT Vendor_id FROM vendors where email = '$email1' "; $result=mysqli_query($conn,$Vendor_id); $row = mysqli_fetch_row($result); $sql = "SELECT Vendor_pricing_id, status, printer_name,process,material,color,strength,surface_finish,per_gram_charge,per_hour_charge FROM vendor_pricing where Vendors_Vendor_id= $row[0]"; $query = mysqli_query($conn, $sql); if (!$query) { die ('SQL Error: ' . mysqli_error($conn)); } if(isset($_POST['submit'])) { $_SESSION['v_id']=$_POST['v_id']; $update=$_POST['v_id']; $p_gram=$_POST['p_gram']; $p_hour=$_POST['p_hour']; $qry=mysqli_query($conn,"UPDATE `vendor_pricing` SET `per_hour_charge`='$p_hour',`per_gram_charge`='$p_gram' WHERE `Vendor_pricing_id`='$update'"); //echo "<meta http-equiv='refresh' content='0'>"; echo '<script type="text/javascript">'; echo 'setTimeout(function () { swal("Updated!","Successfully!","success");'; echo '}, 200);</script>'; //echo "<meta http-equiv='refresh' content='0'>"; } if(isset($_POST['delete'])) { $update=$_POST['v_id']; mysqli_query($conn, "UPDATE vendor_pricing SET status = 'inactive' where Vendor_pricing_id=$update"); echo "<meta http-equiv='refresh' content='0'>"; } if(isset($_POST['link'])) { $update=$_POST['v_id']; $st=$_POST['link']; if($st=="active") { mysqli_query($conn, "UPDATE vendor_pricing SET status = 'inactive' where Vendor_pricing_id=$update"); echo "<meta http-equiv='refresh' content='0'>";} else { mysqli_query($conn, "UPDATE vendor_pricing SET status = 'active' where Vendor_pricing_id=$update"); echo "<meta http-equiv='refresh' content='0'>";} } ?> <div class="box table-responsive no-padding"> <div class="box-header"> <h3 class="box-title">List of all Printers</h3> </div> <!-- /.box-header --> <div id="response" class="box-body"> <table id="example1" class="table table-bordered table-striped" > <thead> <tr> <th>ID</th> <th width="10%">Printer Name</th> <th>Process</th> <th>Material</th> <th>Color</th> <th>Strength</th> <th>Surface Finish</th> <th padding>per Gram</th> <th>per Hour</th> <th >Action</th> </tr> </thead> <tbody> <?php while ($row = mysqli_fetch_array($query)) { $vid=$row['Vendor_pricing_id']; $p_name=$row['printer_name']; $pro=$row['process']; $mat=$row['material']; $color=$row['color']; $type=$row['strength']; $sur=$row['surface_finish']; $p_gram=$row['per_gram_charge']; $p_hour=$row['per_hour_charge']; $st=$row['status']; if ($st=="active"){ $link='inactive';} else { $link='active';} ?> <tr> <form method="post"> <td><?php echo $vid;?> <input type="hidden" value="<?php echo $vid;?>" name="v_id"> </td> <td><?php echo $p_name;?></td> <td><?php echo $pro;?></td> <td><?php echo $mat;?></td> <td><?php echo $color;?></td> <td><?php echo $type;?></td> <td><?php echo $sur;?></td> <td style="padding:9px !important; margin:0px !important;" ><input type="text" style="background:none!important; width:45px; border:none !important; border-color:none;" value="<?php echo $p_gram;?>" name="p_gram"></td> <td style="padding:9px !important; margin:0px !important;"><input type="text" style="background:none!important; width:45px; border:none !important; border-color:none;" value="<?php echo $p_hour;?>" name="p_hour"></td> <td> <button type="submit" name="submit" value="submit" class="btn btn-info btn-small">Update</button> <button type="link" name="link" value="<?php echo $st;?>" class="btn btn-default btn-warning btn-small" style="color:white" ><?php echo $link;?></button> <button type="delete" name="delete" value="delete" class="btn btn-default btn-warning btn-small" style="background:#ED5E68; color:white" >Delete</button> </td> </tr> </form> <?php } ?> </tbody> </table> </div> <!-- /.box-body --> </div> <!-- /.box --> </div> <!-- /.col --> </div> <!-- /.row --> </section> <!-- /.content --> </div> <!-- /.content-wrapper --> <?php include '../footer.php'; ?> </html> 

using echo "<meta http-equiv='refresh' content='0'>"; this line of code I'm able to refresh whole page,, please help how can I reload only table

You cannot reload a specific html element by using a server side script.

You need to research on AJAX which can do exactly what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM