Aqui esta el ultimo archivo, que es donde se hace la consulta a la base de datos:
Código PHP:
<body>
<?php
include("conex.php");
$codbusqueda=$_POST['codbusqueda'];
$env=$_GET["env"];
$result=mysql_query("select dpinv.INV_CODIGO, dpinv.INV_DESCRI, dpinv.INV_CODMAR, dpmarcas.MAR_DESCRI, dpinv.INV_MODELO, dpinv.INV_MATERI, dpinv.INV_TACON, dpinv.INV_COLOR, dpinv.INV_FILBMP FROM dpinv,dpmarcas
WHERE dpinv.INV_CODIGO = '$codbusqueda' AND dpinv.INV_CODMAR = dpmarcas.MAR_CODIGO ");
$row = mysql_fetch_row($result);
$sql = mysql_query("SELECT dpprecios.PRE_CODIGO, dpprecios.PRE_PRECIO, dpinv.INV_CODIGO FROM dpprecios,dpinv WHERE dpinv.INV_CODIGO = '$codbusqueda' AND dpprecios.PRE_CODIGO = dpinv.INV_CODIGO " );
$row1 = mysql_fetch_row($sql);
$sql1 = mysql_query("SELECT DPINV.INV_CODIGO,DPINV.INV_DESCRI,
ROUND(SUM(DPMOVINV.MOV_CANTID*MOV_FISICO*MOV_CXUND )) AS MOV_CANTID
,SUM(DPMOVINV.MOV_CANTID*MOV_FISICO*MOV_CXUND ) AS ANTERIOR
,SUM(IF(MOV_FISICO= 1,DPMOVINV.MOV_CANTID*MOV_CXUND,0)) AS ENTRADA
,SUM(IF(MOV_FISICO=-1,DPMOVINV.MOV_CANTID*MOV_CXUND,0)) AS SALIDA
,SUM(IF(MOV_FISICO= 1,DPMOVINV.MOV_TALL01*MOV_CXUND,0)) AS T1E
,SUM(IF(MOV_FISICO= 1,DPMOVINV.MOV_TALL02*MOV_CXUND,0)) AS T2E
,SUM(IF(MOV_FISICO= 1,DPMOVINV.MOV_TALL03*MOV_CXUND,0)) AS T3E
,SUM(IF(MOV_FISICO= 1,DPMOVINV.MOV_TALL04*MOV_CXUND,0)) AS T4E
,SUM(IF(MOV_FISICO= 1,DPMOVINV.MOV_TALL05*MOV_CXUND,0)) AS T5E
,SUM(IF(MOV_FISICO= 1,DPMOVINV.MOV_TALL06*MOV_CXUND,0)) AS T6E
,SUM(IF(MOV_FISICO= 1,DPMOVINV.MOV_TALL07*MOV_CXUND,0)) AS T7E
,SUM(IF(MOV_FISICO= 1,DPMOVINV.MOV_TALL08*MOV_CXUND,0)) AS T8E
,SUM(IF(MOV_FISICO= 1,DPMOVINV.MOV_TALL09*MOV_CXUND,0)) AS T9E
,SUM(IF(MOV_FISICO= 1,DPMOVINV.MOV_TALL10*MOV_CXUND,0)) AS T10E
,SUM(IF(MOV_FISICO= 1,DPMOVINV.MOV_TALL11*MOV_CXUND,0)) AS T11E
,SUM(IF(MOV_FISICO= 1,DPMOVINV.MOV_TALL12*MOV_CXUND,0)) AS T12E
,SUM(IF(MOV_FISICO= 1,DPMOVINV.MOV_TALL13*MOV_CXUND,0)) AS T13E
,SUM(IF(MOV_FISICO= 1,DPMOVINV.MOV_TALL14*MOV_CXUND,0)) AS T14E
,SUM(IF(MOV_FISICO=-1,DPMOVINV.MOV_TALL01*MOV_CXUND,0)) AS T1S
,SUM(IF(MOV_FISICO=-1,DPMOVINV.MOV_TALL02*MOV_CXUND,0)) AS T2S
,SUM(IF(MOV_FISICO=-1,DPMOVINV.MOV_TALL03*MOV_CXUND,0)) AS T3S
,SUM(IF(MOV_FISICO=-1,DPMOVINV.MOV_TALL04*MOV_CXUND,0)) AS T4S
,SUM(IF(MOV_FISICO=-1,DPMOVINV.MOV_TALL05*MOV_CXUND,0)) AS T5S
,SUM(IF(MOV_FISICO=-1,DPMOVINV.MOV_TALL06*MOV_CXUND,0)) AS T6S
,SUM(IF(MOV_FISICO=-1,DPMOVINV.MOV_TALL07*MOV_CXUND,0)) AS T7S
,SUM(IF(MOV_FISICO=-1,DPMOVINV.MOV_TALL08*MOV_CXUND,0)) AS T8S
,SUM(IF(MOV_FISICO=-1,DPMOVINV.MOV_TALL09*MOV_CXUND,0)) AS T9S
,SUM(IF(MOV_FISICO=-1,DPMOVINV.MOV_TALL10*MOV_CXUND,0)) AS T10S
,SUM(IF(MOV_FISICO=-1,DPMOVINV.MOV_TALL11*MOV_CXUND,0)) AS T11S
,SUM(IF(MOV_FISICO=-1,DPMOVINV.MOV_TALL12*MOV_CXUND,0)) AS T12S
,SUM(IF(MOV_FISICO=-1,DPMOVINV.MOV_TALL13*MOV_CXUND,0)) AS T13S
,SUM(IF(MOV_FISICO=-1,DPMOVINV.MOV_TALL14*MOV_CXUND,0)) AS T14S
,DPESCALAS.ESC_TALL01,DPESCALAS.ESC_TALL02,DPESCALAS.ESC_TALL03,DPESCALAS.ESC_TALL04,
DPESCALAS.ESC_TALL05,DPESCALAS.ESC_TALL06,DPESCALAS.ESC_TALL07,DPESCALAS.ESC_TALL08,
DPESCALAS.ESC_TALL09,DPESCALAS.ESC_TALL10,DPESCALAS.ESC_TALL11,DPESCALAS.ESC_TALL12,
DPESCALAS.ESC_TALL13,DPESCALAS.ESC_TALL14,DPMOVINV.MOV_ESCASO FROM DPINV
LEFT JOIN DPMOVINV ON DPINV.INV_CODIGO=DPMOVINV.MOV_CODIGO INNER JOIN DPESCALAS ON ESC_CODIGO=MOV_ESCASO
WHERE dpinv.INV_CODIGO = '$codbusqueda' AND dpmovinv.MOV_CODIGO = '$codbusqueda' AND(DPMOVINV.MOV_CODALM= '001')
AND (DPMOVINV.MOV_CODSUC= '000001') AND MOV_INVACT=1 AND MOV_FISICO<>0 AND NOT (INV_UTILIZ='R' OR INV_UTILIZ='S')
GROUP BY INV_CODIGO,INV_DESCRI,MOV_ESCASO
HAVING SUM(DPMOVINV.MOV_CANTID*MOV_FISICO)> '' ORDER BY DPINV.INV_CODIGO");
$existencia = mysql_fetch_row($sql1);
/*if (!$row=="")
{
echo "<script>alert('Codigo no existe!')</script>";
echo "<script> window.history.back(-1)</script>";
}
*/
mysql_free_result($result);
mysql_free_result($sql);
mysql_free_result($sql1);
?>
<table width="620" border="0" bordercolor="#FFFFFF" align="center">
<tr>
<td width="500" bordercolor="#F0F0F0" class="fondo"><div align="center">
<p><strong><span class="Estilo8">INVENTARIO</span></strong></p>
</div></td>
</tr>
</table>
<table width="620" border="0" align="center">
<tbody>
<tr>
<td colspan="5" class="fondo"><div align="center" class="Estilo12 Estilo9">RESULTADO DEL CÓDIGO: <strong><?php echo $codbusqueda?></strong></div></td>
</tr>
<tr>
<!-- <form name='formulario' method='post' action='prueba.php' > -->
<td width="106" bgcolor="#CCCCCC"><span class="Estilo17">
<label>Codigo:</label>
</span></td>
<td colspan="1" bgcolor="#CCCCCC" class="inputbox"><strong> <?php echo $row[0]?></strong></td>
<td width="180" rowspan="9" bgcolor="#CCCCCC" ><img src = "<?php echo $row[8] ?>" width="180" height="180" /></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">
<label>Descripcion: </label>
</td>
<td colspan="1" rowspan="1" bgcolor="#CCCCCC" class="inputbox"><strong><?php echo $row[1]?></strong></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">Marca: </td>
<td colspan="1" bgcolor="#CCCCCC" class="inputbox"><strong> <?php echo $row[3]?></strong></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">
<label>Precio: </label>
</td>
<td colspan="1" bgcolor="#CCCCCC" class="inputbox"><strong>
<?php
if ($row1[1] == "")
{
echo $row1[1] = "0.00";
}
else
{
echo $row1[1];
}
?>
</strong></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">
<label>Modelo: </label>
</td>
<td colspan="1" bgcolor="#CCCCCC" class="inputbox"><strong> <?php echo $row[4]?></strong></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">Material: </td>
<td colspan="1" bgcolor="#CCCCCC" class="inputbox"><strong> <?php echo $row[5]?></strong></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">Tacon: </td>
<td colspan="1" bgcolor="#CCCCCC" class="inputbox"><strong> <?php echo $row[6]?></strong></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">Color: </td>
<td colspan="1" bgcolor="#CCCCCC" class="inputbox"><strong> <?php echo $row[7]?></strong></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">Existencia: </td>
<td colspan="1" bgcolor="#CCCCCC" class="inputbox"><strong>
<?php
if ($existencia[2]=="" || $existencia[2]< "0" )
{
echo $existencia[2] = "0";
}
else
{
echo $existencia[2];
}
?>
</strong>
</td>
</tr>
<tr>
<td bgcolor="#CCCCCC" colspan="5" align="right">
<input name="volver" type="button" value="Volver" onclick="window.history.back(-1)" class="boton" />
</td>
</tr>
</tbody>
</table>
</body>
</html>