Código PHP:
$resord=mysql_query("select * from detord where num_dord = '$ord' ",$Conexion);
while($roword=mysql_fetch_array($resord))
{
$i++;
$fam = $roword["fam_dord"];
$sfa = $roword["sfa_dord"];
$ssf = $roword["ssf_dord"];
$art = $roword["art_dord"];
$imp = $roword["imp_dord"];
$cant = $roword["cant_dord"];
$afam[$i]=$fam;
$asfa[$i]=$sfa;
$assf[$i]=$ssf;
$aart[$i]=$art;
$acan[$i]=$cant;
$respro=mysql_query("select * from productos where fam_prod = '$afam[$i]' and sfa_prod = '$asfa[$i]' and ssf_prod = '$assf[$i]' and clave_prod = '$aart[$i]'",$Conexion);
$rowpro=mysql_fetch_array($respro);
if($rowpro)
{
$cve = $rowpro["clave_prod"];
$puni = $rowpro["puni_prod"];
$precio = $rowpro["precio_prod"];
$dsc = $rowpro["dsccorto_prod"];
$imagen = $rowpro["imagen_prod"];
$tot = $puni * $cant;
$tg=$tg + $tot;
$dpuni=number_format($puni,2);
$dtot=number_format($tot,2);
$dtg=number_format($tg,2);
}
echo"<form method=\"POST\" action=\"recalcula.php?cte=$cte&ord=$ord&afam[$i]=$afam[$i]&asfa[$i]=$asfa[$i]&assf[$i]=$assf[$i]&aart[$i]=$aart[$i]&acan[$i]=$acan[$i]&sw=1&i=$i\">";
echo "<tr>"
." <td width=\"106\"><div align=\"center\"><a href=\"cancelar.php?pro=$pro&cat=$cat&scat=$scat&cve=$art&cte=$cte&ord=$ord\">"
." <img title=\" $dsc \" alt=\"$dsc\" src=\"../images/borrar.jpg\" border=\"0\" /></a></div></td>"
." <td width=\"101\"><div align=\"center\"><a href=\"desc.php?pro=$pro&cat=$cat&scat=$scat&cve=$art&cte=$cte&ord=$ord\"><img title=\"$dsc\" alt=\"$dsc\" src=\"../images/$imagen\" border=\"0\" height=\"80\" width=\"80\" /></a></div></td>"
." <td width=\"211\"><a href=\"desc.php?pro=$pro&cat=$cat&scat=$scat&cve=$art&cte=$cte&ord=$ord\">$dsc</a></td>"
." <td align=\"center\" width=\"60\"> 15</td>"
." <td align=\"center\" width=\"60\">"
."<input size=\"4\" value=\"$acan[$i]\" name=\"acan[$i]\" >"
."<input type=\"image\" src=\"../images/recalcula.jpg\" name=\"sub\">"
." <td width=\"96\"><div align=\"center\">$ $dpuni</div></td>"
." <td width=\"96\"><div align=\"center\">$ $dtot</div></td>"
." </tr>";
$sw = 1;
$precio = 0;
}
recalcula.php
Código PHP:
$respro=mysql_query("select * from productos where fam_prod = '$afam[$i]' and sfa_prod = '$asfa[$i]' and ssf_prod = '$assf[$i]' and clave_prod = '$aart[$i]'",$Conexion);
$rowpro=mysql_fetch_array($respro);
if($rowpro)
{
$exis = $rowpro["exis_prod"];
}
if($acan[$i] > $exis)
{
echo"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\""
. "\"http://www.w3.org/TR/html4/loose.dtd\">"
. "<html>"
. "<head>"
. "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">"
. "<title>COMPRA DE LA TIENDA VIRTUAL 50Y50</title>"
. "</head>"
. "<body>";
echo "<div align=\"center\">"
. " <table border=\"0\" cellpadding=\"0\" style=\"border-collapse: collapse\" width=\"760\" id=\"table1\">"
. " <tr>"
. " <td align=\"center\" valign=\"top\">"
. " <table border=\"0\" width=\"760\" cellspacing=\"0\" cellpadding=\"0\" id=\"table2\">"
. " <tr>"
. " <td width=\"153\">"
. " <img border=\"0\" src=\"../images/logo.jpg\" width=\"106\" height=\"60\"></td>"
. " <td align=\"center\" width=\"456\">"
. " <img border=\"0\" src=\"../images/tv.jpg\" width=\"400\" height=\"51\"></td>"
. " <td align=\"center\" width=\"150\">"
. " </td>"
. " </tr>"
. " </table>"
. " </tr>"
. " </table>"
. "<p> </p>"
. "<table width=\"301\" border=\"0\" align=\"center\">"
. " <tr>"
. " <td><p align=\"center\" class=\"Estilo1\">Cantidad seleccionada excede a la existencia </p>"
. " <p align=\"center\" class=\"Estilo2\">Intente de nuevo </p></td>"
, " </tr>"
- "</table>";
echo"<META HTTP-EQUIV=\"refresh\" content=\"3;URL=compra.php?cte=$cte&ord=$ord&&afam[$i]=$afam[$i]&sfa[$i]=$sfa[$i]&ssf[$i]=$ssf[$i]&aart[$i]=$aart[$i]&acan[$i]=$acan[$i]&sw=1&i=0\">";
}
else
{
$i = 1;
while ($acan[$i] > 1) {
$result=("UPDATE `detord` SET cant_dord ='$acan[$i]' where num_dord = '$ord' and fam_dord = '$afam[$i]' and sfa_dord = '$asfa[$i]' and ssf_dord = '$assf[$i]' and art_dord = '$aart[$i]'");
mysql_query($result,$Conexion);
$x="UPDATE `detord` SET cant_dord ='$acan[$i]' where num_dord = '$ord' and fam_dord = '$afam[$i]' and sfa_dord = '$asfa[$i]' and ssf_dord = '$assf[$i]' and art_dord = '$aart[$i]'"; echo $x,"<br>";
$i++;
}