我有以下代码,其中我执行了一段时间,但我希望在一个区域的每个段中放置一行和它的合计,然后继续其余部分
下面是我的代码:
$resultado = $conexion->query("
SELECT Det.OP
, Det.ID_Area
, Det.Cliente
, de.Desc_Area
, sum(Det.Cantidad) as CantidadOP
, sum(Det.Volumen) as VolumenOP
, sum(Det.PrecioTotal) as PrecioTotalOP
from Despacho_DetalleEntreAreas as Det
join Despacho_DescEntreAreas as de
on de.ID_Area = Det.ID_Area
where Det.Fecha Between '$FDesde' and '$FHasta'
Group by Det.OP
, Det.ID_Area
order by Det.ID_Area
, Det.OP asc
");
while($row=$resultado->fetch_assoc())
{
$PrecioGrupo=$PrecioGrupo + $row['PrecioTotalOP']; ?>
<tr>
<td><?php echo $row['ID_Area'];?></td>
<td><?php echo $row['Desc_Area'];?></td>
<td><?php echo $row['OP'];?></td>
<td><?php echo $row['Cliente'];?></td>
<td><?php echo $row['CantidadOP'];?></td>
<td><?php echo number_format($row['VolumenOP'],4,"." , ",");?></td>
<td><?php echo "$". "". number_format($row['PrecioTotalOP'],0, " " , ",");?></td>
</tr>
这是我的桌子:
<table class="table table-bordered hover" id="Tabla_OpDespachadas_Areas" cellspacing="0">
<thead>
<tr>
<th>ID_AREAS</th>
<th>AREAS</th>
<th>CLIENT</th>
<th>CANT</th>
<th>VOL</th>
<th>PRICE</th>
</tr>
</thead>
<tbody>
<?php if (isset($_POST['Bto_Procesar'])): ?>
<?php include("Clases/ProcesoOP.php") ?>
<?php endif; ?>
</tbody>
我想要这样的东西。在面积的每一段的末尾,我想要放一行总和,求出该面积的总价,然后继续计算,我画了一个我想看的表
---------------------------------------------
|id|area |CLIENT |CANT |VOL |PRICE |
|--|-----------|--------|-----|------|--------|
|1 |area1 |xxx1 |10 |1 |1 |
|1 |area1 |xxx2 |10 |1 |2 |
|1 |area1 |xxx3 |20 |2 |3 |
| | | | | |6 |
|--|-----------|--------|-----|------|--------|
|2 |area2 |xxx1 |40 |1 |5 |
|2 |area2 |xxx2 |45 |1 |5 |
|2 |area2 |xxx3 |20 |2 |5 |
| | | | | |15 |
我希望我的问候解释清楚了。
发布于 2018-08-18 05:32:39
这段PHP代码应该会添加您要查找的小计。
<?php
$resultado = $conexion->query("SELECT Det.OP,Det.ID_Area,Det.Cliente,de.Desc_Area,
sum(Det.Cantidad) as CantidadOP,
sum(Det.Volumen) as VolumenOP,
sum(Det.PrecioTotal) as PrecioTotalOP
from Despacho_DetalleEntreAreas as Det
inner join Despacho_DescEntreAreas as de on de.ID_Area = Det.ID_Area where Det.Fecha Between '$FDesde' and '$FHasta'
Group by Det.OP, Det.ID_Area
order by Det.ID_Area, Det.OP asc");
$currArea = '';
$currTotal = 0;
while($row=$resultado->fetch_assoc()) {
$PrecioGrupo = $PrecioGrupo + $row['PrecioTotalOP'];
if($currArea != $row['ID_Area']) {
if($currArea != '') {
echo " <tr>\r\n";
echo " <td colspan='6'> </td>\r\n";
echo " <td>$".number_format($currTotal,0, " " , ",")."</td>\r\n";
echo " <tr>\r\n";
}
$currArea = $row['ID_Area'];
$currTotal = 0;
}
$currTotal += $row['PrecioTotalOP'];
?>
<tr>
<td><?php echo $row['ID_Area'];?></td>
<td><?php echo $row['Desc_Area'];?></td>
<td><?php echo $row['OP'];?></td>
<td><?php echo $row['Cliente'];?></td>
<td><?php echo $row['CantidadOP'];?></td>
<td><?php echo number_format($row['VolumenOP'],4,"." , ",");?></td>
<td><?php echo "$". "". number_format($row['PrecioTotalOP'],0, " " , ",");?></td>
</tr>
<?php
echo " <tr>\r\n";
echo " <td colspan='6'> </td>\r\n";
echo " <td>$". number_format($row['PrecioTotalOP'],0, " " , ",")."</td>\r\n";
echo " <tr>\r\n";
}
echo " <tr>\r\n";
echo " <td colspan='6'> </td>\r\n";
echo " <td>$".number_format($currTotal,0, " " , ",")."</td>\r\n";
echo " <tr>\r\n";
?>
https://stackoverflow.com/questions/51902816
复制相似问题