Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/10/2009, 04:15
futbolregional
 
Fecha de Ingreso: agosto-2008
Mensajes: 71
Antigüedad: 15 años, 8 meses
Puntos: 2
Problema con un bucle

Buenas amigos del foro, a ver si alguien me puede ayudar, puesto que se me han acabado las posibilidades de como hacerlo.
Tengo un albaran el cual inserto a una BBDD y lo que quiero hacer es poder modificar varias filas a la vez.

Esta es la insercion que hago, pero solo me modifica un campo. creo que me falta un bucle pero no se como hacerlo....

$sqlAlbaran="SELECT * FROM albaran WHERE albaran=".$_GET['albaran'];
$resultAlbaran=mysql_query($sqlAlbaran,$idcon);
$filasAlbaran=mysql_fetch_assoc($resultAlbaran);
$filas=mysql_num_rows($resultAlbaran);
if(isset($_POST['Enviar'])){
$albaran=$_POST['Albaran'];
$fecha=$_POST['Fecha'];
$ano=$_POST['Ano'];
$cliente=$_POST['Cliente'];
$direccion=$_POST['Direccion'];
$poblacion=$_POST['Poblacion'];
$telefono=$_POST['Telefono'];
$date=time();

$x=$filasAlbaran['idAlbaran'];
$ml=number_format($_POST['Cantidad'.$x.'']*$_POST['Largo'.$x.''],2);
$m2=number_format($_POST['Cantidad'.$x.'']*($_POST['Largo'.$x.'']*$_POST['Ancho'.$x.'']),2);
$sqlInsert="UPDATE albaran SET albaran='$albaran', ano='$ano', fecha='$fecha', cliente='$cliente', direccion='$direccion', poblacion='$poblacion', telefono='$telefono', cantidad='".$_POST['Cantidad'.$x.'']."', largo='".$_POST['Largo'.$x.'']."', ancho='".$_POST['Ancho'.$x.'']."', grueso='".$_POST['Grueso'.$x.'']."', descripcion='".$_POST['Descripcion'.$x.'']."', m2='$m2', ml='$ml', date=$date WHERE idAlbaran=".$_POST['id'.$x.''];
mysql_query($sqlInsert,$idcon);
//header('location:modificar_albaran.php?user='.$_GE T['user'].'&albaran='.$albaran);
}

Este seria el formulario de envio, donde le doy un nombre distinto a cada campo con un bucle a traves de la id de la base de datos.

<?php
$sqlAlbaran="SELECT * FROM albaran WHERE albaran=".$_GET['albaran']." ORDER BY idAlbaran ASC";
$resultAlbaran=mysql_query($sqlAlbaran,$idcon);
$filas=mysql_num_rows($resultAlbaran);
while($filasAlbaran=mysql_fetch_assoc($resultAlbar an)){
$campo=$filasAlbaran['idAlbaran'];
echo '<tr>
<td width="5%" height="25" align="center" valign="middle"><input name="Cantidad'.$campo.'" type="text" class="campo" id="Cantidad'.$campo.'" size="2" maxlength="3" value="'.$filasAlbaran['cantidad'].'"/></td>
<td width="8%" height="25" align="center" valign="middle"><input name="Largo'.$campo.'" type="text" class="campo" id="Largo'.$campo.'" size="8" maxlength="8" value="'.$filasAlbaran['largo'].'"/></td>
<td width="8%" height="25" align="center" valign="middle"><input name="Ancho'.$campo.'" type="text" class="campo" id="Ancho'.$campo.'" size="8" maxlength="8" value="'.$filasAlbaran['ancho'].'"/></td>
<td width="5%" height="25" align="center" valign="middle"><input name="Grueso'.$campo.'" type="text" class="campo" id="Grueso'.$campo.'" size="1" maxlength="2" value="'.$filasAlbaran['grueso'].'"/></td>
<td width="30%" height="25" align="center" valign="middle"><input name="Descripcion'.$campo.'" type="text" class="campo" id="Descripcion'.$campo.'" size="40" maxlength="70" value="'.$filasAlbaran['descripcion'].'"/></td>
<td width="10%" height="25" align="center" valign="middle"><input name="id'.$campo.'" type="text" class="campo" id="id'.$campo.'" size="40" maxlength="10" value="'.$filasAlbaran['idAlbaran'].'"/></td>
<td width="10%" height="25" align="center" valign="middle">&nbsp;</td>
<td width="12%" height="25" align="center" valign="middle">&nbsp;</td>
<td width="12%" height="25" align="center" valign="middle">&nbsp;</td>
</tr>';
}
?>

Bueno si alguien me puede echar una mano lo agradeceria... Un saludo