如图所示,我有 2 个立即付款按钮,但是如何在按下按钮时从行获取数据并输出到模式中。如果我这样做 $row[' paymentAmount']
它每次都会显示最后一行。如何将按钮与行关联起来,以便它在模式中显示正确的金额?
<div class='payment_container'>
<div class='row col-md-12 custyle'>
<table class='table table-striped custab'>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Ammount</th>
<th>Due Date</th><?php if ($_SESSION['renterID'] == 0) {
echo "<th class='text-center'>Paid?</th>";
} else {
echo "<th class='text-center'>Action</th>";
}
?>
</tr>
</thead><?php
include_once 'includes/database.php';
if ($_SESSION['renterID'] == 0){
$sql = "SELECT firstName, lastName, paymentID, paymentAmount, paymentDate, paymentPaid FROM renter, payment WHERE renter.renterID = payment.renterID ORDER BY paymentDate ASC";
} else {
$sql = "SELECT firstName, lastName, paymentID, paymentAmount, paymentDate, paymentPaid FROM renter, payment WHERE renter.renterID = payment.renterID AND $_SESSION[renterID] = renter.renterID";
}
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
while($row = $result->fetch_assoc()) {
echo
"<tr>
<td>$row[paymentID]</td>
<td>$row[firstName] $row[lastName]</td>
<td>$row[paymentAmount]</td>
<td>";echo date ('F d, Y', strtotime($row['paymentDate'])); echo "</td>";
if ($_SESSION['renterID'] == 0) {
if ($row['paymentPaid'] == '0') {
echo "<td class='text-center'><a class='btn btn-danger btn-sm'><i class='fa fa-times' aria-hidden='true'>Paid</i></a></td>";
} else {
echo "<td class='text-center'><a class='btn btn-success btn-sm'><i class='fa fa-check' aria-hidden='true'>Paid</i></a></td>";
}
} else {
if ($row['paymentPaid'] == '0'){
echo "<td class='text-center'><button href='#' class='btn btn-success btn-sm' data-toggle='modal' data-target='#pay_now' name='payNowID' value='$row[paymentAmount]'><i class='fa fa-usd' aria-hidden='true'>Pay Now</i></button><input type='hidden' </td>";
} else {
echo "<td class='text-center'><a class='btn btn-sm'><i class='fa fa-check' aria-hidden='true'>Paid</i></a></td>";
}
}
echo "</tr>";
}
} else {
echo "<tr><td colspan='5'>No payments at this time</td></tr>";
}
?>
</table>
</div>
谢谢!抱歉,如果这没有意义,因为我对 PHP 很陌生并且正在尝试学习。
最佳答案
只需使用单击按钮的行的 ID。
关于php - 输出2时如何从第一行获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47465319/