RE: [PHP-ES] Agrupar
| From: | Marco Eyzaguirre | Date: | Tue, 13 May 2003 22:42:57 +0000 |
| Subject: | RE: [PHP-ES] Agrupar | ||
| References: | 1 | Groups: | php.general.es |
| Request: | Send a blank email to general-es+get-36168@lists.php.net to get a copy of this message | ||
Obviamente esta sin probar y se puede mejorar mucho, pero ahí tienes la
idea. (esta en postgres, es muy simple cambiar de DBMS)... Si se me ha
escapado algo, sorry ;)
Saludos
Marco
<?
$conexion = pg_pconnect("dbname=base1 port=5432");
$sentencia = "select p.cod_prove,p.desc_prove,q.dato1,q.monto from
proveedor p,datos q where p.cod_provee=q.cod_provee";
$exe = pg_exec($conexion,$sentencia);
$n = pg_numrows($exe);
$fila = pg_fetch_array($exe,0);
$antiguo = $fila[0];
$suma_x_provee += $fila[0];
echo "
<tr>
<td>Cod Provee : $fila[0]</td>
<td>Desc Provee : $fila[1]</td>
</tr>
<tr>
<td>$fila[2]</td>
<td>$fila[3]</td>
</tr>";
for ($f=1;$f<=$n-1;++$f)
{
$fila = pg_fetch_array($exe,$f);
if ($fila[0]!=$antiguo)
{
echo "
<tr>
<td>Cod Provee : $fila[0]</td>
<td>Desc Provee : $fila[1]</td>
</tr>
<tr>
<td>TOTAL DE PROVEEDOR $fila[1] : </td>
<td>$suma_x_provee</td>
</tr>";
$suma_x_provee = 0;
}
echo "
<tr>
<td>$fila[2]</td>
<td>$fila[3]</td>
</tr>";
$suma_x_provee += $fila[0];
}
?>
-----Mensaje original-----
De: Maximiliano Yedid [mailto:yo@maximilianoyedid.com]
Enviado el: Martes, 13 de Mayo de 2003 02:27 p.m.
Para: lista@phpes.com
Asunto: [PHP-ES] Agrupar
Quiero hacer un select con group by, y despues imprimir el resultado de
la consulta en forma agrupada, y que salga el titulo del grupo.
como lo hago?
gracias
maxi