我正在从数据库中检索数据并将其显示在标签中,我正在尝试使用Java脚本从数据库中捕获主键作为按钮的值。我该怎么做?
我已尝试使用带in while循环和outside while循环的javascript尝试此操作,但失败。 while ($row = mysqli_fetch_assoc($records)) {}
<?php
while ($row = mysqli_fetch_assoc($records)) {
?>
<div class="col-lg-4 ">
<div class="card" style="width:22rem;">
<div class="card-body" >
<!-- <div class="card" style="width: 25rem;height: 30rem;background-color:OFFWHITE ;">
<p class="card-text" >--> <label>Customer Name:</label>
<?php echo $row['Name'];?><br>
<label>Phone Number:</label>
<?php echo $row['phoneno'];?><br>
<?php $ticketid = $records['ticketid']; ?>
<form method="post">
<select class="form-control" name="status">
<option value="Open" selected>Open</option>
<option value="Pending">Accept</option>
<option value="Reject">Reject</option>
</select>
<button id="ticket" value="<?php echo $row['ticketid'];?>" onclick="myFunction()" class="btn">Submit</button>
</form>
<!-- </p> -->
</div>
</div>
</div>
<?php
}
?>
<script>
function myFunction(){
var ticketid = "<?php echo $records['ticketid'];?>";
var x = document.getElementById("ticket").value;
alert(x);
//alert(ticketid);
//echo $status;
}
</script>
我想捕获显示在div(在卡片视图中)的div上显示的每个数据的主键。我该怎么办?