Tabla con Subtotales y grupos

Doc q tal nose si me puedas ayudar tengo este código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</head>
<body>
<?php
$cn = mysql_connect("localhost","root","170207");
mysql_select_db("economia",$cn);
$sql = "select * from tabla order by grupo";
$result = mysql_query($sql);
$row_consulta = mysql_fetch_assoc($result);
$totalRows_consulta = mysql_num_rows($result);
?>
<table width="500" border="1" style="border-collapse:collapse;" bordercolor="#000000">
<?php do{ ?>
<?php
$grupoant=$grupo;
$grupo=$row_consulta['grupo'];
$smonto[] = $row_consulta['monto'];
$tmonto[] = $row_consulta['monto'];
?>
<?php if($grupoant != $grupo){?>
<tr>
<td colspan="4" align="center" bgcolor="#CCCCCC"><strong>GRUPO <?php echo $row_consulta['grupo'] ?></strong></td>
</tr>
<?php } ?>
<tr>
<th><?php echo $row_consulta['id']; ?></th>
<th><?php echo $row_consulta['nombre'] ?></th>
<th><?php echo $row_consulta['email'] ?></th>
<tD style="TEXT-ALIGN: right" ><?php echo $row_consulta['monto'] ?></tD>
</tr>
<?
if($grupoant != $grupo){ ?>
<tr class="SubTotal">
<td colspan="3"><strong>Subtotal:</strong></td>
<td style="TEXT-ALIGN: right" valign="baseline"><B><?php printf("%.2f",array_sum($smonto)); ?></B></td>
</tr>
<?php
$smonto=array();
}
} while ($row_consulta = mysql_fetch_assoc($result));?>
<tr class="Total">
<td colspan="3" bgcolor="#999999"><strong>Total:</strong></td>
<td style="TEXT-ALIGN: right" valign="baseline" bgcolor="#999999"><b><?php printf("%.2f",array_sum($tmonto)); ?></b></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($result);
?>
lo q me genera esta tabla:
http://localhost/problema.JPG
lo q necesito es q me aparesca los subtotales por grupo:
tengo grupo A, B, C, D asi mismo hay una columna de montos de los cuales quiero sacar el subtotal y total general, espero me puedas ayudar
Gracias

1 respuesta

Respuesta
No se como son las tablas ni organizas los datos, pero busca ayuda sobre "querys group" y encontrarás ayuda para querys de agrupado:
http://www.forosdelweb.com/f86/ayuda-con-query-count-group-533182/

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas