PHP foreach Group and add results

0

I have the following case:

I need to group results of a query in the field RS.id_servicio, according to an array and add the results of the fields RS.servicio_cantidad and RS.servicio_preciototal.

I leave the code of what I did, the result is correct, but it does not group the results or add the fields.

<table>
<?php
include ("includes/conexion.php");

$RemitosSeleccionados=$_POST['idremitoregistro'];

echo '<thead>';
echo '<tr>';
echo '<th>IdRemito</th>';
echo '<th>Remito Nº</th>';
echo '<th>Cantidad</th>';
echo '<th>Servicio</th>';
echo '<th>Precio Unitario</th>';
echo '<th>Total</th>';
echo '</tr>';
echo '</thead>';

foreach($RemitosSeleccionados as $fila) {

$result = mysql_query("SELECT RS.id_servicioenremito, RS.id_remito, RS.id_servicio, RS.id_cliente, RS.id_empleado, SUM(RS.servicio_cantidad) AS servicio_cantidad, RS.servicio_preciounitario, SUM(RS.servicio_preciototal) AS servicio_preciototal, RS.TotalServicios, remitos.remito_numero, listasyservicios.nombreservicio
FROM serviciosenremitos RS
INNER JOIN remitos ON remitos.id_remito_registro = RS.id_remito
INNER JOIN listasyservicios ON listasyservicios.id_listasyservicios = RS.id_servicio
WHERE id_remito = '$fila'
GROUP BY RS.id_servicio

");

if ($row= mysql_fetch_array($result)){ 
			do { 
echo '<tbody>';
echo '<tr>';
echo '<td>'.$row["id_remito"].'</td>';
echo '<td>'.$row["remito_numero"].'</td>';
echo '<td>'.$row["servicio_cantidad"].'</td>';
echo '<td>'.$row["id_servicio"].'</td>';
echo '<td>'.$row["servicio_preciounitario"].'</td>';
echo '<td>'.$row["servicio_preciototal"].'</td>';
echo '</tr>';
echo '</tbody>';
			} while ($row = mysql_fetch_array($result)); 
			} else { 
ECHO 'No existe el servicio.';
			}

}



?>

</table>
    
asked by pointup 29.05.2018 в 18:29
source

0 answers