gpt4 book ai didi

php - 重新加载表格而不刷新php中的整个页面

转载 作者:行者123 更新时间:2023-11-29 10:27:55 24 4
gpt4 key购买 nike

我正在从数据库中获取表中的数据,有三个按钮更新、删除和事件/非事件按钮,这三个按钮都有自己的功能,但在事件发生后它必须重新加载表中更新的数据。我能够重新加载整个页面,但我只想重新加载表格内容,我对 Javascript 和 ajax 的了解较少。我没有找到继续使用 ajax 的正确方法。请帮助我完成任何可以的程序可以解决我的问题..我如何正确地集成到我的代码中。

<?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>

使用 echo "<meta http-equiv='refresh' content='0'>";这行代码我可以刷新整个页面,请帮助我如何仅重新加载表格

最佳答案

您无法使用服务器端脚本重新加载特定的 html 元素。

您需要研究 AJAX,它可以完全满足您的要求。

关于php - 重新加载表格而不刷新php中的整个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47940800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com