PHP - Sumatoria de horas

 
Vista:

Sumatoria de horas

Publicado por juan luis (1 intervención) el 21/07/2006 01:32:42
saludos a todos

tengo un problemita

quiero sumar horas desde php haciendo la consulta a Mysql

aqui esta mi codigo:
//MUESTRA EL DESPLEGADO DE LOS SITIOS
echo "<table width='100%' border='1' bordercolor='#999999' cellspacing='5' > \n";
echo "<tr>
<td BGCOLOR='#0066cc' align='center' NOWRAP><b>NOMBRE DEL SITIO</b></td>
<td BGCOLOR='#0066cc' align='center' NOWRAP><b>FECHA DE INSTALACION</b></td>
<td BGCOLOR='#0066cc' align='center' NOWRAP><b>CITA</b></td>
<td BGCOLOR='#0066cc' align='center' NOWRAP><b>INGENIERO IDC</b></td>
<td BGCOLOR='#0066cc' align='center' NOWRAP><b>INGENIERO SUPERVISOR</b></td>
<td BGCOLOR='#0066cc' align='center' NOWRAP><b>TIEMPO DE INTERVENCION</b></td>
</tr> \n";
/* AGREGO UNA VARIABLE PARA SUMAR LOS DATOS */
$sumatoria = 0;
while ($row = mysql_fetch_row($mes)){
echo "<tr>
<td align='center' NOWRAP>$row[0]</td>
<td align='center' NOWRAP>$row[1]</td>
<td align='center' NOWRAP>$row[2]</td>
<td align='center' NOWRAP>$row[3]</td>
<td align='center' NOWRAP>$row[4]</td>
<td align='center' NOWRAP>$row[5]</td>
</tr> \n";
/* ACA ES DONDE AGREGAS LA VARIABLE PARA SUMAR LOS DATOS */
$sumatoria = $row[5] + $sumatoria;
}
/*ACA AGREGAS EL PEDAZO DE TABLA QUE MOSTRARA LA SUMATORIA*/
echo "<tr>
<td align='center' colspan='6'>Sumatoria: ".$sumatoria."</td>
</tr>";
/* LISTO */
echo "</table> \n";
mysql_free_result($mes);

yo hice los calculos a mano y si es muy diferente de lo que me sale en SUMATORIA, a mano me salen 62 horas y con el codigo me salen 18.

alguien me puede decir en donde esta mi error?
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Sumatoria de horas

Publicado por alberto (26 intervenciones) el 22/07/2006 00:04:14
<?php
$sumatoria = 0;
while ($row = mysql_fetch_row($mes)){
echo "<tr>
<td align='center' NOWRAP>$row[0]</td>
<td align='center' NOWRAP>$row[1]</td>
<td align='center' NOWRAP>$row[2]</td>
<td align='center' NOWRAP>$row[3]</td>
<td align='center' NOWRAP>$row[4]</td>
<td align='center' NOWRAP>$row[5]</td>
</tr> \n";
/* ACA ES DONDE AGREGAS LA VARIABLE PARA SUMAR LOS DATOS */
/*-----------------------------------------*/
$sumatoria = $row[5] + $sumatoria;
/*--------------------------------*/
}
echo $sumatoria ;

?>

tu codigo esta bien echo, si arroja un error el error no esta en esta parte
asi que quisas esto te pueda servir para descubrirlo

¿que tipo de datos es $row[5]? ya que sumar o restar fechas no es lo mismo
que sumar o restar enteros puede que el error este en la base de datos o quisas es un string intenta usar algo asi

$sumatoria = parseInt($row['5']) + sumatoria ;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar