各行の2列の乗算が必要です。これは私のコードとスクリプトです。このスクリプトは機能していますが、ちょうど最初の行のために、このスクリプトの出力は次のようになります。jQueryで2列の乗算
2行目の結果が間違っている:
<form>
<table id="my-table">
<?php
$query3 = mysqli_query($con,"select * from orders") or die("sdfsfs");
while($row3=mysqli_fetch_array($query3))
{
$quantity = $row3['quantity'];
$unit_price = $row3['unit_price'];
//$total = $quantity * $unit_price;
?>
<tr>
<td><input type="text" class="common quantity" name="1" id="quant" value="<?php echo $quantity; ?>"></td>
<td><input type="text" class="common price" name="2" id="units" value="<?php echo $unit_price; ?>"></td>
<td><input type="text" class="total" name="3" id="total" readonly></td>
</tr>
<?php } ?>
<tr>
<td colspan="2"><label class="form-control">Subtotal</label></td>
<td><input name="subtotal" readonly id="subtotal" class="sub" type="text" /></td>
</tr>
</table>
</form>
jQueryの
<script>
$(".total").each(function() {
$('.total').val(parseFloat($('#quant').val()) * parseFloat($('#units').val()));
});
</script>
あなたは 'idは=「合計」を持っています'/' id = "quant" '... while whileループ - *間違い*。 IDは一意でなければならない – Justinas