Ver Mensaje Individual
  #11 (permalink)  
Antiguo 14/05/2009, 08:55
Avatar de colote
colote
 
Fecha de Ingreso: julio-2008
Ubicación: Rosario - Santa Fe - Argentina
Mensajes: 729
Antigüedad: 15 años, 10 meses
Puntos: 8
Respuesta: Consultando 2 veces con IN (SELECT ....

Hola gente !!! Gracias a uds lo pude resolver !!!
Me quedo asi !!!! Les dejo el codigo completo para que lo vean

Código:
$pagina=1;
$cont=0;

$clientes=mysql_query("SELECT * FROM clientes WHERE 
cod_cli BETWEEN $desde AND $hasta 
AND
cod_cli IN(SELECT cod_cli FROM pedidos
UNION ALL
SELECT cod_cli FROM presup)",$conexion);

while($cli=mysql_fetch_array($clientes)){

?>

<table>
	<tr><td class='l1' colspan='6'><b><?php echo "(".$cli['cod_cli'].")"?> - <?echo $cli['razon_soc']?></b></td></tr>
</table>
<?php
$cont++;   // INCREMENTO PARA EL TITULO CLIENTE


/////////////// C O M I E N Z A   P E D I D O S //////////
$pedidos=mysql_query("SELECT * FROM pedidos where cod_cli=$cli[cod_cli]",$conexion);

while($ped=mysql_fetch_array($pedidos)){

$fec_ped = explode("-", $ped['fecha_ped']);

?>

<table>
<tr><td class='l1' colspan='6'><?php echo $ped['tipo'] ?> - <?php echo $ped['codigo'] ?> - <?echo "$fec_ped[2]/$fec_ped[1]/$fec_ped[0]"?></td></tr>
</table>
<?php
$subpedidos=mysql_query("SELECT * FROM sub_pedidos as sped
inner join items as it on sped.cod_item=it.cod_item
where cod_pedido=$ped[codigo]
order by sped.fecha_ent",$conexion);

while($sped=mysql_fetch_array($subpedidos)){
$fec_ent_ped = explode("-", $sped['fecha_ent']);
?>
<table>
<tr>
<td class="l2"><?echo $sped['cod_item']?> - <?echo $sped['nombre_item']?></td>
<td class="l3"><?echo $sped['cantp']?></td>
<td class="l3"><?echo $sped['cant_ent']?></td>
<td class="l3"><?echo $sped['cant_rest']?></td>
<td class="l4"><?echo "$fec_ent_ped[2]/$fec_ent_ped[1]/$fec_ent_ped[0]";?></td>
</tr>
</table>
<!-- ////////// T E R M I N A  P E D I D O S///////////// -->

<?php
}
}
?>

<?php
/////////////// C O M I E N Z A  P R E S U P U E S T O S //////////
$presup=mysql_query("SELECT * FROM presup where cod_cli=$cli[cod_cli]",$conexion);

while($pre=mysql_fetch_array($presup)){

$fec_pre = explode("-", $pre['fecha_presup']);

?>

<table>
<tr><td class='l1' colspan='6'><?php echo $pre['tipo'] ?> - <?php echo $pre['codigo'] ?> - <?echo "$fec_pre[2]/$fec_pre[1]/$fec_pre[0]"?></td></tr>
</table>
<?php
$subpresup=mysql_query("SELECT * FROM sub_presup as spre
inner join items as it on spre.cod_item=it.cod_item
where cod_presup=$pre[codigo]
order by spre.fecha_ent",$conexion);

while($spre=mysql_fetch_array($subpresup)){
$fec_ent_pre = explode("-", $spre['fecha_ent']);
?>
<table>
<tr>
<td class="l2"><?echo $spre['cod_item']?> - <?echo $spre['nombre_item']?></td>
<td class="l3"><?echo $spre['cantp']?></td>
<td class="l3"><?echo $spre['cant_ent']?></td>
<td class="l3"><?echo $spre['cant_rest']?></td>
<td class="l4"><?echo "$fec_ent_pre[2]/$fec_ent_pre[1]/$fec_ent_pre[0]";?></td>
</tr>
</table>
<!-- ////////// T E R M I N A  P R E S U P U E S T O S ///////////// -->
<?php
}
} 


}  // cierre while clientes
ACA se ve como funciona ... por cada cliente muestra sus PED y PRE, solo en el caso del cliente 130 tiene PED y PRE ...

Saludos, y gracias !!!
__________________
Mail: [email protected]