Código SQL:
Ver original
$sql = ( " SELECT ps.prodescuadria,ps.prodlargo,SUM(ps.prodvolumen) AS totalvolumen,COUNT(prodescuadria),COUNT(prodlargo),prodpzas FROM esquemaprograma AS ep JOIN simulaciones AS s ON (s.profolio=ep.profolio) AND (ep.esqcodigo=s.esqcodigo) AND (ep.patcodigo=s.patcodigo) JOIN produccionsimulada AS ps ON (s.simcodigo=ps.simcodigo) WHERE ep.profolio='$variable' AND ep.patcodigo='$variable1' AND prodtipo!='C' GROUP BY prodescuadria,prodlargo,prodvolumen,prodpzas ORDER BY prodvolumen DESC " );
Y la recorro de la siguiente manera
Código PHP:
Ver original
if($_POST["buscar"] != ''){ $cont = $_POST["cont-oculto"]; for($i = 1; $i <= $cont; $i++){ $variable = $_POST["campo".$i]; $variable1 = $_POST["campo1".$i]; echo '<br />'; $sumavol = 0; $sql = ( " SELECT ps.prodescuadria,ps.prodlargo,SUM(ps.prodvolumen) AS totalvolumen,COUNT(prodescuadria),COUNT(prodlargo),prodpzas FROM esquemaprograma AS ep JOIN simulaciones AS s ON (s.profolio=ep.profolio) AND (ep.esqcodigo=s.esqcodigo) AND (ep.patcodigo=s.patcodigo) JOIN produccionsimulada AS ps ON (s.simcodigo=ps.simcodigo) WHERE ep.profolio='$variable' AND ep.patcodigo='$variable1' AND prodtipo!='C' GROUP BY prodescuadria,prodlargo,prodvolumen,prodpzas ORDER BY prodvolumen DESC " ); $result = pg_query ( $dbconn, $sql ) or die ("ERROR EN CONSULTA"); //Contador de Enumeradcion $cont = 1; while( $row = pg_fetch_object($result) ){ $sumavol = $row->volumentotal; } echo $sumavol; if( pg_num_rows($result) != 0 ){ $suma = 0; while( $row = pg_fetch_assoc($result) ){ ?> <tr> <td background="imag/bg_menuon.gif"><?php echo $cont++; ?></td> <td><?php echo $row["prodescuadria"]; ?></td> <td><?php echo $row["prodpzas"]; $suma_pzas = $suma_pzas + $row["prodpzas"]; ?></td> <td><?php /*suma volumen por folio */ // $suma = $suma + $row["prodvolumen"]; ?></td> <td><?php $porcent = $row["prodvolumen"] / $row["totalvolumen"]; echo $porcent; ?></td> <?php } /*suma volumen total de folio*/ $suma_todo = $suma_todo + $suma; /*suma porcentaje total = 100%*/ $suma_porcent = $suma_porcent + $suma_porce; } } }
GRACIAS POR AYUDAR !!