我有数据库表BuildingMaster,其中包含三个字段ID,BuildingLocation和Status。我有PHP页面,该页面在HTML表中显示所有建筑物详细信息,例如ID,Location,Status。在每一行中都有删除超链接。
当我单击链接时,相关记录已从数据库中删除。但它仍显示在HTML表中。当我刷新网页时,它将被删除。
Building.PHP
WHERE
SYSTEM.REGION.REGION_STATUS_CODE = N'1'
AND SYSTEM.STATE.STATE_STATUS_CODE = N'1'
AND SYSTEM.ORDERS.DISCARDED_DATE IS NULL
AND SYSTEM.SERVICE.SERVICE_DISCARDED_DATE IS NULL
AND SYSTEM.SERVICE.SERVICE_STATUS_CODE = N'01'
AND (
(SYSTEM.ORDERS.DISCOUNT_CODE = N'N/A'
AND SYSTEM.SERVICE.SERVICE_CONTRACT_CODE = N'Retail')
OR
(SYSTEM.ORDERS.DISCOUNT_CODE != N'N/A'
AND SYSTEM.SERVICE.SERVICE_CONTRACT_CODE = N'Wholesale')
)
buildingremove.php
<!DOCTYPE html>
<html>
<head>
<script type = "text/javascript" src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
function Remove(ID) {
$.ajax({
type: "POST",
url: "buildingremove.php",
data: {ID:ID},
dataType: "JSON",
success: function(data) {
$("#Row"+ID).remove();
$("#Response").html(data.MSG);
},
error: function(err) {
$("#Response").html(err);
}
});
}
</script>
</head>
<body>
<table>
<tr>
<th>ID</th>
<th>Location</th>
<th>Status</th>
<th>Action</th>
</tr>
<?php
$sq="Select * from buildingmaster";
$Table=mysqli_query($CN,$sq);
while ($Row=mysqli_fetch_array($Table)) {
$ID=$Row['ID'];
echo("<tr id='Row'.$ID.'>");
echo("<td>".$Row["ID"]."</td>");
echo("<td>".$Row["BuildingLocation"]."</td>");
echo("<td>".$Row["Status"]."</td>");
echo("<td>");
echo("<a href='#' onclick='Remove($ID)'>Delete</a>");
echo("</td>");
echo("</tr>");
}
?>
</table>
<?php
echo("<div>");
echo("<p id='Response'></p>");
echo("</div>");
?>
</body>
</html>
答案 0 :(得分:1)
ajax正在运行,数据库已更新,但是删除无法运行,因为代码找不到所需的行。 分配行ID的语法不正确
替换此:
echo("<tr id='Row'.$ID.'>");
与
echo("<tr id='Row".$ID."'>");
或者简单地按照Quasimodo的建议
echo("<tr id='Row$ID'>");