
consulta complicada
Publicado por LLUIS (68 intervenciones) el 21/12/2007 10:10:52
tengo una consulta complicada que no me funciona como quisiera
quiero mostrar el total de horas que han realizado todos los trabajadores de un mismo encargado en una fecha determinada, luego tengo 2 juegos de registros, uno que muestra todos los trabajadores del encargado, y la otra que calcula el total de horas para cada trabajador, y no me sale nada, cuando por listado si que veo horas de algunos trabajadores
las consultas son:
$query_TREB = "SELECT * FROM TREBALLADORS WHERE CODIEMPRESA = ".$CODIEMPRESA." AND ENCARREGAT = ".$CODIUSUARI." ORDER BY NOMTREBALLADOR ASC";
$TREB = mysql_query($query_TREB, $LLUIS) or die(mysql_error());
$row_TREB = mysql_fetch_assoc($TREB);
$totalRows_TREB = mysql_num_rows($TREB);
$query_HORES = "SELECT SUM(UNITATS) AS SUMA FROM PARTES WHERE IDTIPUS=0 AND CODIEMPRESA=".$CODIEMPRESA." AND CODITREBALLADOR=".$row_TREB['CODITREBALLADOR']." AND DATAPARTE='".$DIASQL."' GROUP BY CODITREBALLADOR, CODIEMPRESA, DATAPARTE";
$HORES = mysql_query($query_HORES, $LLUIS) or die(mysql_error());
$row_HORES = mysql_fetch_assoc($HORES);
$totalRows_HORES = mysql_num_rows($HORES);
y en el body
<?php do { ?>
<tr>
<td><?php echo $row_TREB['NOMTREBALLADOR']; ?> </td>
<?php $row_HORES = mysql_fetch_assoc($HORES); ?>
<td><?php echo $row_HORES['SUMA']; ?> </td>
</tr>
<?php } while ($row_TREB = mysql_fetch_assoc($TREB)); ?>
gracias y feliz navidad
quiero mostrar el total de horas que han realizado todos los trabajadores de un mismo encargado en una fecha determinada, luego tengo 2 juegos de registros, uno que muestra todos los trabajadores del encargado, y la otra que calcula el total de horas para cada trabajador, y no me sale nada, cuando por listado si que veo horas de algunos trabajadores
las consultas son:
$query_TREB = "SELECT * FROM TREBALLADORS WHERE CODIEMPRESA = ".$CODIEMPRESA." AND ENCARREGAT = ".$CODIUSUARI." ORDER BY NOMTREBALLADOR ASC";
$TREB = mysql_query($query_TREB, $LLUIS) or die(mysql_error());
$row_TREB = mysql_fetch_assoc($TREB);
$totalRows_TREB = mysql_num_rows($TREB);
$query_HORES = "SELECT SUM(UNITATS) AS SUMA FROM PARTES WHERE IDTIPUS=0 AND CODIEMPRESA=".$CODIEMPRESA." AND CODITREBALLADOR=".$row_TREB['CODITREBALLADOR']." AND DATAPARTE='".$DIASQL."' GROUP BY CODITREBALLADOR, CODIEMPRESA, DATAPARTE";
$HORES = mysql_query($query_HORES, $LLUIS) or die(mysql_error());
$row_HORES = mysql_fetch_assoc($HORES);
$totalRows_HORES = mysql_num_rows($HORES);
y en el body
<?php do { ?>
<tr>
<td><?php echo $row_TREB['NOMTREBALLADOR']; ?> </td>
<?php $row_HORES = mysql_fetch_assoc($HORES); ?>
<td><?php echo $row_HORES['SUMA']; ?> </td>
</tr>
<?php } while ($row_TREB = mysql_fetch_assoc($TREB)); ?>
gracias y feliz navidad
Valora esta pregunta


0