gpt4 book ai didi

php - 单击每行中的按钮时,如何更新显示 sql 数据的 html 表行?

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

当我单击问题按钮时,允许单击第一行按钮。第二排按钮不起作用。所以我想更新我想要的表行。

这是界面 - 第一行仅在单击第二行时更新,不允许单击问题按钮。

Interface Table

这里是带有ajax脚本的itemdisplay.php页面。

<?php
include('../db_connector.php');

$req = $_GET['cat1'];

$query = "select i.item_name ,r.qty, i.item_id , r.reqID, r.av from items i
JOIN req_items r on r.item_name = i.item_id
JOIN req rq on r.req_number = rq.req_number
WHERE i.status = 'common' AND
rq.req_number = $req and r.status = 'approved'
GROUP BY i.item_name ";

$result = mysqli_query($con,$query);

?>

<table class="table table-hover" >
<thead>
<tr>
<th>#</th>
<th>Item Name</th>
<th>Quantity</th>
<th>Stock Available </th>


</tr>
</thead>
<tbody>
<?php
@$count = mysqli_num_rows($result);
$itemCount = 1;
if($count > 0) {
while ($row = mysqli_fetch_array($result)) {

$name = $row['item_name'];
$qty = $row['qty'];
$id = $row['item_id'];
$rqId = $row['reqID'];
$av = $row['av'];


$query1 = "select m.stock_level
from main_stock m
where m.item_id = $id and m.depot_id = 27";

$result1 = mysqli_query($con, $query1);

@$count = mysqli_num_rows($result1);
if ($count > 0) {
while ($row = mysqli_fetch_array($result1)) {

$level = $row['stock_level'];

?>

<tr id="mydiv">

<td><?php echo $itemCount; ?></td>
<td hidden><input class="form-control" name="rqId"
type="text" id="rqId" readonly value="<?php echo $rqId; ?>"></td>
<td><input class="form-control" name="name" type="text"
id="name" readonly value="<?php echo $name; ?>"></td>
<td><input class="form-control" name="qty" type="text"
id="qty" readonly value="<?php echo $qty; ?>"></td>
<td><input class="form-control" name="level" type="text"
id="level" readonly value="<?php echo $level; ?>"></td>
<td hidden><?php echo $av; ?></td>


<?php
if($level < $qty) {

if ($av != 1) {

echo 'Do not exists the available stock !!';
?>
<td><button class="btn btn-primary" type="submit"
id="request" name="request">Request</button></td>


<?php

} else
{

?>

<td><p>Processing</p></td>


<?php
}

?>
<?php

} else
{


?>

<td><button class="btn btn-primary" type="submit"
id="issue" name="issue">Issue</button></td>
<?php

}

?>


</tr>
<?php
$itemCount++;
}
}
}
}
else{
echo 'No records found';
}


?>
</tbody>
</table>

<script>



$('#issue').click(function(){

$.ajax({
url:"./ajax/cIssue.php",
method:"POST",
data:$('#rqId').serialize(),
success:function(data)
{
$("#mydiv").load(location.href + " #mydiv");
}
});
});
</script>

这是cIssue.php查询文件

<?php
include('../db_connector.php');

$id = $_POST["rqId"];

$query = "";

$query = "UPDATE `req_items`
SET `status` = 'issue'
WHERE `reqID`=$id";
$result = mysqli_query($con, $query);
echo "Item Issued !";

$r = "UPDATE `main_stock`
SET `stock_level` = `stock_level` - (select `qty`
from `req_items`
where `reqID`= $id )
WHERE `depot_id`='27' and `item_id`= (select `item_name`
from `req_items`
where `reqID`= $id ) ";

$l = mysqli_query($con, $r);




?>

当我单击“问题”按钮时,我想更新我想要的任何行。如果您想了解有关我的代码的更多详细信息,我可以提供。

最佳答案

您好,您正在使用元素的 id 进行单击,这就是它仅识别第一个“问题”按钮的原因。请使用类来代替“问题”按钮的单击事件。

$(".myIssuebtn").on("click",function(){
//your ajax call here.

});
<button class="btn btn-primary" class="myIssuebtn" type="submit" 
id="issue" name="issue">Issue</button>

关于php - 单击每行中的按钮时,如何更新显示 sql 数据的 html 表行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57264460/

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