Ver Mensaje Individual
  #33 (permalink)  
Antiguo 02/04/2009, 09:10
Avatar de vidalsoft
vidalsoft
 
Fecha de Ingreso: julio-2008
Ubicación: /www/...
Mensajes: 339
Antigüedad: 16 años, 7 meses
Puntos: 1
reporte php por grupos y subtotales

Hola amigos de foros del web.
quiero hacer un reporte quebrados por grupo y por cada grupo el subtotal (que es la suma de los montos por grupo)

la tabla es:

Código PHP:
CREATE TABLE  `economia`.`tabla` (
  `
codint(10unsigned NOT NULL auto_increment,
  `
nombrevarchar(45NOT NULL default '',
  `
grupovarchar(45NOT NULL default '',
  `
montodecimal(9,2NOT NULL default '0.00',
  
PRIMARY KEY  (`cod`)
ENGINE=InnoDB DEFAULT CHARSET=latin1
y mi codigo es:
Código PHP:
<table class="Grid" cellspacing="0" cellpadding="0">
        <tr class="Row">
          <td colspan="4"><strong>Fecha: </strong><strong><?php echo strftime ("%d/%m/%Y"); ?></td>
        </tr>
        <tr class="Caption">
          <th>Id</th> 
          <th>Nombre</th>
          <th>Grupo</th>
          <th>Monto</th>
           </tr>      
        
        <?php
         
do{ ?>
<?php 
$grupoant
=$grupo;
$grupo=$row['grupo'];
?>
<?php
if($grupoant != $grupo){
?>         
<tr class="Row">
<td colspan="4"><strong>Dependencia: <?php echo $row["grupo"]; ?></strong></td>
</tr>        
<?php }        
?>
<tr class="Row">
          <td>
            <p align="center"><?php echo $row["cod"]; ?></p></td> 
          <td>
            <p align="center"><?php echo $row["nombre"]; ?></p></td> 
          <td>
            <p align="center"><?php echo $row["grupo"]; ?></p></td> 
          <td>
            <p align="center"><?php echo $row["monto"]; ?></p></td> 
        </tr>
          <?php 
        
if($grupoant !=$grupo){

 
?>
<tr class="SubTotal">      
          <td>&nbsp;</td> 
          <td>&nbsp;</td>   
          <td><strong>Subtotal:</strong></td> 
          <td style="TEXT-ALIGN: right" valign="baseline"><?php printf("%.2f",array_sum($sub_total_monto)); ?></td> 
        </tr>
        <?php 
             $sub_total_monto
=array();
                } 
            
$sub_total_monto[]= $row['monto'];
            
$total_monto[] = $row['monto'];        
         
?>
    <?php        } while ($row=mysql_fetch_assoc($result)); ?>

       <tr class="Total">
          <td colspan="4" align="right"><?php  printf("%.2f",array_sum($total_monto)); ?></td> 
        </tr>
</table>
estoy usando para las sumas de subtotales y para el total general la funcion array_sum()

pero me imprime asi:


cuando deberia imprimir los subtotales al cambiar de grupo osea debe imprimir la fila de subtotales al finalizar cada grupo.

espero su ayuda compañeros
gracias de antemano
__________________
Anthony Vidal Contreras | @AnthonyVidalC | Skype: vidalsystem | [email protected]