我有一个从数据库填充的动态表。我的代码如下:如何求和从数据库填充的值
<table class="table table-bordered" id="tb">
<thead>
<tr style="BACKGROUND-COLOR: DarkGrey ">
<th colspan="5" style="text-align:Center;">Objectives</th>
</tr>
<tr class="tr-header">
<th style="text-align:Center;width:10%;">ID</th>
<th colspan="2">Targets</th>
<th style="text-align:Center;width:1%;" rowspan="2">Weightage %</th>
</tr>
<tr>
<th> </th>
<th> </th>
<th style="width:10%;"> Date </th>
</tr>
</thead>
<tbody
<?PHP
$myquery = "select subtotals,Serial_Number,Targets,Weightage, row_number,edit_details
from Table1 WHERE Serial_Number='$Serial_Number' ORDER BY Row_Number asc";
$fetched = sqlsrv_query($conn, $myquery);
if ($fetched === false) {
die(print_r(sqlsrv_errors(), true));
}
while ($res = sqlsrv_fetch_array($fetched, SQLSRV_FETCH_ASSOC)) {
$Weightage = $res['Weightage'];
$Targets = $res['Targets'];
$Row_Number = $res['row_number'];
$subtotals = $res['subtotals'];
?>
<tr id="<?php //echo $id ?>" class="tredit">
<td class="edittbl">
<b><input type="text" name="ID[]" class="ASDF form-control" id="Row<?php echo $Row_Number ?>" value="<?php echo $Row_Number; ?>" readonly></input></b>
</td>
<?PHP
if ($Objectives == "SubTotal") {
?>
<td class="edittbl" colspan="3">
<b><input type="text" name="Subtotal[]" class=" ASDF form-control" value="<?php echo $Objectives; ?>" style="text-align:center;" readonly ></input></b>
</td>
<td class="edittbl">
<b><input type="text" name="SubTotal_Weightage[]" class="ASDF form-control" value="<?php echo $Weightage; ?>" readonly></input></b>
</td>
<?PHP
} else {
?>
<td class="edittbl">
<input type="text" name="Targets[]" class="ASDF form-control" value="<?php echo $Targets; ?>" ></input>
</td>
<td class="edittbl">
<input type="text" name="Weightage[]" class="ASDF form-control" value="<?php echo $Weightage; ?>"></input>
</td>
<?PHP } ?>
</tr>
<?PHP } ?>
</tbody>
</table>
我试图做小计一自动计算,当值发生改变,这样当的权重发生变化时,小计自动计算并给出了新的价值。
这些weightages是动态的,并且小计的DONOT具有固定的位置。我如何确保如果前四项有任何变化,第一小计会发生变化,如果第二项和第三项有变化,它会改变第二项小计?
希望有任何建议。
非常重要的一点。没有两个输入可以在同一页*中具有相同的ID *。核实。 'id =“Row <?php echo $ Row_Number?>”'每个输入都有相同的id。 –