我试图创建一个模块,每当检查复选框时,数据库中指示的价格将添加到总费用中,并将显示结果。如何从数据库(sql)中获取值/插入 php 代码并显示所选框的结果?
<script>
function updateTextArea() {
var allVals = [];
$('#c_b :checked').each(function() {
allVals.push($(this).val());
});
$('#t').val(allVals)
}
$(function() {
$('#c_b input').click(updateTextArea);
updateTextArea();
});
索引.php
$queryPaymentLab = "select * from requestedlab where patient_ID='6' AND paid='0'";
$resultPaymentLab = mysql_query($queryPaymentLab);
$countRowsPaymentLab=mysql_num_rows($resultPaymentLab);
if($countRowsPaymentLab > 0){
while($fetchLab=mysql_fetch_array($resultPaymentLab)){
$labservice_ID=$fetchLab['labservice_ID'];
$queryPrice = "select * from labservices where labservice_ID='".$labservice_ID."'";
$resultPrice = mysql_query($queryPrice);
$fetchPrice=mysql_fetch_array($resultPrice);
$labService=$fetchPrice['labService'];
$labPrice=$fetchPrice['labPrice'];
$totalLab+=$labPrice;
$totalHBill+=$labPrice;
echo "<tr><td><input type='checkbox' name='labservice_ID' value='$labservice_ID'/></td>
<td>Laboratory</td><td>$labService</td><td>$totalHBill</td></tr>";
}
}
显示总费用..
$queryPrice = "select * from labservices where labservice_ID='".$labservice_ID."'";
$resultPrice = mysql_query($queryPrice);
while($fetchPrice=mysql_fetch_array($resultPrice)){
$labPrice=$fetchPrice['labPrice'];
$total+=$labPrice;
}
echo "<strong>Total:</strong>
<strong>$total</strong>";