以下代码工作正常,但是当我尝试将值保存到数据库时,它无法显示该值。
更准确地说,它可以显示不到一秒钟,我可以看到数据库中的值在我眼前闪现,然后值仍然是保存之前的原始值。
我希望能够从db检索值并更新值。 例如,如果已支付某一行付款,则更新的金额将保存到数据库。
现在,我可以将其保存到db,但无法回显db值以进行进一步更新
这里是php代码
<td><textarea class="total_sum_value" rows="" cols="5" style="border: none" name="total[]"><?php echo $row['total'] ?></textarea> </td>
<td><textarea class="arrears" rows="" cols="5" style="border: none" name="arrears[]"><?php echo $row['arrears'] ?></textarea> </td>
任何想法都将不胜感激。感谢
$(document).ready(function() {
$("#myTable").on('input', '.txtCal, .status', function() {
calculate();
});
function calculate() {
var calculated_total_sum = 0;
var to_be_paid = 0;
$("#myTable tr").each(function() {
var get_textbox_value = $('.txtCal', this).val();
var get_payment_status = $('.status', this).val();
if (get_textbox_value && get_payment_status) {
if ($.isNumeric(get_textbox_value)) {
calculated_total_sum += parseFloat(get_textbox_value);
}
if (get_payment_status === 'N') {
to_be_paid += parseFloat(get_textbox_value);
}
}
});
$("#total_sum_value").html(calculated_total_sum);
$("#arrears").html(to_be_paid);
}
calculate();
});
&#13;
<?php
include_once('connect-db.php');
if (isset($_POST['submit'])){
foreach ($_POST['patientid'] as $index => $patientid) {
$id = mysql_real_escape_string($_POST['id'][$index]);
$data23 = mysql_real_escape_string($_POST['total'][$index]);
$data24 = mysql_real_escape_string($_POST['arrears'][$index]);
mysql_query("UPDATE table SET patientid ='$data1',hkid ='$data20',treatmentname3='$data5', totalnooftreatment='$data6',
nthtreatment='$data7',date='$data8',nextdate='$data9',skip='$data10',language='$data11',smsorcall='$data17',
engmessage='$data14',status='$data15',nurse='$data16',paymentmethod='$data22', price='$data18',paystatus='$data19',remark='$data21'
,total='$data23',arrears='$data24'
WHERE id=$id") or die(mysql_error());
header("Location: displaypatientall.php");
}
}
?>
&#13;
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body>
<table id="myTable">
<tr>
<th width="100">Name </th>
<th>Price</th>
<th>Payment status</th>
</tr>
<tr>
<td><span>A</span></td>
<td><input type="text" class='txtCal' value="50" /></td>
<td><input type="text" class='status' value="Y" /></td>
</tr>
<tr>
<td><span>B :</span></td>
<td><input type="text" class='txtCal' value="10" /></td>
<td><input type="text" class='status' value="Y" /></td>
</tr>
<tr>
<td><span>C:</span></td>
<td><input type="text" class='txtCal' value="10" /></td>
<td><input type="text" class='status' value="N" /></td>
</tr>
<tr>
<td><span><b>TOTAL :</b></span></td>
<td><b><span id="total_sum_value"></span></b></td>
</tr>
<tr>
<td><span><b>Yet to be paid</b></span></td>
<td><b><span id="arrears"></span></b></td>
</tr>
&#13;