为什么单击时无法从表中的行中获取 IDPending
这是代码:
<!-- ############################################################################################################################################################################################################ -->
<!-- TABLE BUSINESS -->
<div class="row" id="TblBiz" style="display: none;">
<div class="col" style="height: 71px;">
<h1 style="font-family: Roboto, sans-serif; font-weight: 300;">Business</h1>
</div>
<div class="col-md-8 offset-md-2">
<div class="panel" id="main">
<div class="container-fluid container-bg">
<div class="table-responsive">
<table id="myTable4" class="table table-hover table-dark" style="font-size:11px; margin-top:6px;">
<thead style="font-size: 18px;">
<th>#</th>
<th>Business ID</th>
<th>Name</th>
<th>Owner</th>
<th>View</th>
<th>Approval</th>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM mechanic_business";
$result = mysqli_query($connect, $sql);
if(mysqli_num_rows($result) > 0){
$i = 1;
while ($row = mysqli_fetch_assoc($result)) {
$biz_ID = $row['businessID'];
$mech_ID = $row['mechID'];
$mech_name = $row['mech_name'];
$bizName = $row['business_name'];
$bizApprove = $row['business_approval_status'];
$bizStatus = $row['business_status'];
// $dateJoin = $row['DATE_REGISTERED'];
// $dateFormated = date("d M Y", strtotime($dateJoin));
// Color class in PHP color(Pending, Approved, Banned)
$color = ($bizApprove === 'Pending') ? '#f0ad4e' : (($bizApprove === 'Approved') ? '#28a745' : '#dc3545');
echo "<tr style='font-size:18px;'>";
echo "<td class='align-middle'>" . $i; $i++ . "</td>";
echo "<td class='align-middle'>" . $biz_ID . "</td>";
echo "<td class='align-middle'>". $bizName ."</td>";
echo "<td class='align-middle'>". $mech_name ."</td>";
echo "<td class='align-middle'><input type='button' name='view' value='view' id='". $biz_ID ."' class='btn btn-info btn-xs view_biz'></td>";
echo "<td class='align-middle'><a role='button' class='approval-bton' id='". $biz_ID ."' style='color:". $color ."';>". $bizApprove ."</a></td>";
echo "</tr>";
}
} else {
echo "<tr>";
echo "<td colspan='7' class='table-active align-middle'>No Record in Database</td>";
echo "</tr>";
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- ############################################################################################################################################################################################################ -->
<!-- ############################################################################################################################################ -->
<!-- UPDATE APPROVE STATUS MODAL -->
<div class="modal fade" id="approveModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"> Update Business Approval Status </h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="" method="post" enctype="multipart/form-data">
<div class="modal-body">
<input type="text" name="businessID" id="" value="<?php echo $biz_ID; ?>">
<div class="form-group">
<div>
<small id="photoHelp" class="form-text text-muted"><span style="color: #FF0000;">*</span><em>320px x 320px is ideal dimension, Format: jpg, png, jpeg, and PDF only</em></small>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" name="updateApprove" class="btn btn-primary">Save Change</button>
</div>
</form>
</div>
</div>
</div>
<!-- ############################################################################################################################################ -->
当我从每一行单击 a时,它假设会根据数据库Pending
获取它们,但是当我从每一行单击时,它们显示的结果与下面链接中的图片相同。ID
ID
https://drive.google.com/file/d/1IcfDUs3Q8Wl5vVO3KF793M5noTukLrCL/view?usp=sharing
它们都显示ORVA01BIZ-00000002
但在数据库中第一行是ORVA01BIZ-00000001
并且ORVA01BIZ-00000002
是第二行并且继续。
有非常简单的逻辑。
当循环结束时,它只会打印模型中的最后一行 biz_id。
解决方案是: -
您必须在代码中进行的更改
如果您想获取每个 id,您必须做一件事
这是你的第二个 td :-
echo "<td class='align-middle bizzid'>" . $biz_ID . "</td>";
在您的模型中,您必须粘贴以下内容:-
<input type="text" name="businessID" id="businessID" value="">
-此 jquery 代码可以帮助您获得所需的结果。
var bizid = $(this).closest('tr').find('.bizzid').text();
$('#businessID').val(bizid);
$('#approveModal').modal('show');
});'
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句