Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/01/2010, 07:58
midgardo2002
 
Fecha de Ingreso: enero-2010
Mensajes: 11
Antigüedad: 14 años, 3 meses
Puntos: 0
Pregunta problema con multi update php/mysql

Hola soy nuevo gracias por aceptarme en el foro, tengo un problema ando haciendo un pequeño sistema de facturacion, primero se hace una consulta a la bd para saber cuantos registros estan pendientes en estatus ORDEN y de ahi se hace un arreglo donde se almacenan, etc etc., en un for se muestra el arreglo en una tabla, hay un segundo for para numerar los registros y asignarles el numero de la factura siguiente, el problema es cuando quiero actualizar la bd, me agrega el ultimo numero en todos los campos de la tabla en estatus ORDEN, no se que hacer ya probe varias cosas y yo creo que el problema esta en el query update, pero no he podido hacer que me agregue la secuencia y no que me repita el ultimo numero, aqui agrego el codigo espero alguien me pueda ayudar, gracias.


Código:
<script languaje="javascript">
function fact()
{
document.forma.action="factrad.php";
document.forma.method="POST";
document.forma.submit();
}
</script>

<SCRIPT TYPE="text/javascript">
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
	if (keycode == 13)
	{
	myfield.form.submit();
	return false;
	}
	else
	return true;
}

</SCRIPT>

<?php
$nomb3=$dato2;
$tiempo= time();
$hora=date("h:i A",$tiempo);
$fecha=date("d/m/Y");

echo "<h6>HOLA $nomb3 QUE OPERACION DESEAS REALIZAR <p align=right> fecha:$fecha hora:$hora</h6>";

$conn =mysql_connect("localhost","root","");
mysql_select_db("fact",$conn);



$query="select * from factrad where estatus='orden'";
$res=mysql_query($query,$conn);
if(mysql_num_rows($res)!=0)
{
			echo "<html>";
			echo "<title></title>";
			echo "<head><h2><center> LISTA DE FACTURAS EN ESTATUS ORDEN</center></h2>";
			echo "</head>";
?>
	<body  onLoad="this.document.forma.num.focus();">
	<?php		//	echo "<center><img src=logo.jpg height=150 width=120></center>";
			echo "<input type=hidden name=dato2 value='$nomb3' style=width:265px; height:30px ></center>";
			echo "<pre>";
			//echo "<br>";
			echo "<form name='forma' id='forma'>";
			$impf="IMPRIMIR FACTURAS";
			$valor=chop($impf);
			echo "<p align=CENTER> <input type=button value='$valor' onclick=location.href='factrad.php'></p>";
			echo "<table align='left' width='225' cellspacing='2' cellpadding='2'border='1'>";
			echo "<tr>";
			echo "<td readonly=readlonly><b>ID</td>";
			echo "<td readonly=readlonly><b>CLAVE USUARIO</td>";
			echo "<td readonly=readlonly><b>SIGLAS</td>";
			echo "<td readonly=readlonly><b>RAZON SOCIAL</td>";

			echo "</tr>";

	while($row=mysql_fetch_array($res))
	{
		    $id[]=$row["id"];
		    $cve[] = $row ["cveusuario"];
    		$sigla[] = $row ["siglasradio"];
    		$razon[] = $row ["razonsoc"];

/*
			echo "<tr>";
			echo "<td><input type=text name='' size='15' style='text-align:center' maxlenght='100' readonly='readonly' value='$row[id]'></td>";
			echo "<td><input type=text name='' size='15' style='text-align:center' maxlenght='100' readonly='readonly' value='$row[cveusuario]'></td>";
			echo "<td><input type=text name='' size='15' style='text-align:center' maxlenght='100' readonly='readonly' value='$row[siglasradio]'></td>";
			echo "<td><input type=text name='' size='65' style='text-align:center' maxlenght='100' readonly='readonly' value='$row[razonsoc]'></td>";
			echo "<td><input type=text name='num' size='15' style='text-align:center' maxlenght='100' ></td>";
			echo "</tr>";
*/
	}

			echo "<tr>";
			echo "<td><input type=text size=1 readonly='readonly'></td>";
			echo "</tr>";


			$t = count($id);



for ($i = 0; $i < $t; $i++)
{
			echo "<tr>";
			echo "<td><input type=text name='clave' size='15' style='text-align:center' maxlenght='100' readonly='readonly' value='$id[$i]'></td>";
			echo "<td><input type=text name='clave' size='15' style='text-align:center' maxlenght='100' readonly='readonly' value='$cve[$i]'></td>";
			echo "<td><input type=text name='sigg' size='15' style='text-align:center' maxlenght='100' readonly='readonly' value='$sigla[$i]'></td>";
			echo "<td><input type=text name='razz' size='65' style='text-align:center' maxlenght='100' readonly='readonly' value='$razon[$i]'></td>";

}



echo "</tr>";
			echo "</table>";
			echo "<table width='225' cellspacing='2' cellpadding='2' border=1>";
			echo "<tr><td readonly=readlonly><b>NUMERAR </td></tr>";
			echo "<tr><td><input type=text name='num' size='10' style='text-align:center' maxlenght='100'  value=''><input type=submit value='numerar'></td></tr>";



		for($b=0; $b<$t; $b++)
			{
			$c=$num++;
			echo "<tr><td><input type=text size='15' name='numera' style='text-align:center' maxlenght='100' readonly=readonly value=$c></td></tr>";
	//		echo $c;
			echo $b;
			$zz[]=$c;

// query para actualizar la bd y agregar el numero de factura a los registros que aun no lo tienen en base a la consulta previa
//	 $insertar="update factrad set numfact=$numera where estatus='orden'";
//	  mysql_query($insertar, $conn);
			}
$zm=count($zz);

		for($d=0; $d<$t; $d++)
			{
			echo $zz[$d];
		//	query para actualizar la bd y agregar el numero de factura a los registros que aun no lo tienen en base a la consulta previa
			$insertar=mysql_query("update factrad set numfact=$zz[$d] where $id[$d] AND estatus='orden'");
			}


			echo "</table>";

			echo "</form>";
			echo "</pre>";
			echo "</html>";


}


?>