gpt4 book ai didi

javascript - 如何计算上一行并显示在表格的当前行中?

转载 作者:行者123 更新时间:2023-12-02 22:21:06 25 4
gpt4 key购买 nike

我正在使用 codeigniter 从表中获取一些数据

我的 table 图片 enter image description here这是我从表中获取的表。在这个表中,我将第一行中的余额列显示为 10,下一行显示为 35,我如何使用 java 脚本或 php 本身来计算此值。

我的代码:

<table class="table datatable-button-html5-basic">
<thead>
<tr><h6>
<th class="col-sm">Bill No</th>
<th class="col-sm" >Date</th>
<th class="col-sm" >Particulars</th>
<th class="col-sm" >Op.Stock</th>
<th class="col-sm-7">Pur/Prod</th>
<th class="col-sm" >Sales/Cons</th>
<th class="col-sm" >Balance</th>

</tr>
</thead>
<tbody>
<?php foreach ($query as $row): ?>
<tr>
<?php $total = 0;
$total += $row['qty']; ?>
<td>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row['orderno'];?></td>
<td ><?php echo $row['orderdate'];?></td>
<td >PRODUCTION</td>
<td></td>
<td dir="rtl"><?php echo $row['qty'];?></td>
<td></td>
<td><?php echo "$total" ;?></td>

</tr><?php endforeach ?>
<tr><?php foreach ($query1 as $row1): ?>
<td>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row1['billno'];?></td>
<td ><?php echo $row1['billdate'];?></td>
<td ><?php echo $row1['accName'];?></td>
<td></td>
<td></td>
<td dir="rtl"><?php echo $row1['salesqty'];?></td>
<td></td>
</tr>
<?php endforeach ?>
</tbody>

这是我的表代码。我的另一个示例表:enter image description here

最佳答案

foreach之前定义$balance,并将余额列的每一行求和为$balance += $total;

 <table class="table datatable-button-html5-basic">
<thead>
<tr><h6>
<th class="col-sm">Bill No</th>
<th class="col-sm" >Date</th>
<th class="col-sm" >Particulars</th>
<th class="col-sm" >Op.Stock</th>
<th class="col-sm-7">Pur/Prod</th>
<th class="col-sm" >Sales/Cons</th>
<th class="col-sm" >Balance</th>

</tr>
</thead>
<tbody>
<?php

$balance = 0;
foreach ($query as $row): ?>
<tr>
<?php $total = 0;
$total += $row['qty'];
$balance += $total;
?>
<td>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row['orderno'];?></td>
<td ><?php echo $row['orderdate'];?></td>
<td >PRODUCTION</td>
<td></td>
<td dir="rtl"><?php echo $row['qty'];?></td>
<td></td>
<td><?php echo "$total" ;?></td>

</tr><?php endforeach ?>
<tr><?php foreach ($query1 as $row1): ?>
<td>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row1['billno'];?></td>
<td ><?php echo $row1['billdate'];?></td>
<td ><?php echo $row1['accName'];?></td>
<td></td>
<td></td>
<td dir="rtl"><?php echo $row1['salesqty'];?></td>
<td></td>
</tr>
<?php endforeach ?>
</tbody>

关于javascript - 如何计算上一行并显示在表格的当前行中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59223914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com