因此,我选择了一个表,其中状态为='pending' 我将编辑和删除按钮添加到每一行 我想做的是,当我单击编辑按钮时,它将自动更新 列状态为“已批准”。 因此,基本上我只希望单击“编辑”按钮来更新它,因为列状态只有2个值。待审批。
这是我的代码
<?php
$connect = mysqli_connect("localhost", "root", "", "lms");
$query = "select p.id,
p.empno,fname,lname,loan,amount,amortization,term,dateapplied,dateupdated
FROM application p INNER JOIN accounts a ON p.empno = a.empno WHERE p.status
= 'pending'";
$result = mysqli_query($connect, $query);
?>
<div class="container" style="width:1000px;">
<div class="table-responsive">
<br />
<div id="employee_table">
<table class="table table-bordered">
<tr>
<th>Transaction No</th>
<th>Name</th>
<th>Employee No</th>
<th>Type</th>
<th >Amount</th>
<th >Terms</th>
<th>Amortization</th>
<th>Date</th>
<th colspan = "2" width="7%">Approved</th>
</tr>
<?php
while($row=mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["id"]; ?></td>
<td><?php echo $row["fname"]." ".$row["lname"]; ?></td>
<td><?php echo $row["empno"]; ?></td>
<td><?php echo $row["loan"]; ?></td>
<td><?php echo number_format($row["amount"],2); ?></td>
<td><?php echo $row["term"]; ?></td>
<td><?php echo $row["amortization"]; ?></td>
<td><?php echo $row["dateapplied"]; ?></td>
<td><input type="button" name="update" value="YES" id="<?php echo
$row["id"]; ?>" /></td>
<td><input type="button" name="del" value="NO" id="<?php echo $row["id"];
?>" /></td>
</tr>
<?php
}
?>
</table>
下一步我该怎么做?而且我还需要更新每个行。
答案 0 :(得分:0)
您可以将类添加到按钮:
<input type="button" name="del" class="editbtn" value="NO" id="<?php echo $row["id"];
并通过类名调用ajax,并通过this.id获取当前的按钮ID:
$(".editbtn").click(function(){
var id = this.id;
$.ajax({url: "test.php?id="+id, success: function(result){
$("#div1").html(result);
}});
});