Foros del Web » Programando para Internet » PHP »

Como modificar varios registros desde un formulario

Estas en el tema de Como modificar varios registros desde un formulario en el foro de PHP en Foros del Web. Saludos nuevamente a todos los genios del foro, y agradezco la ayuda que siempre me han dado, cada día aprendo algo nuevo de ustedes, solo ...

  #1 (permalink)  
Antiguo 11/12/2009, 14:49
 
Fecha de Ingreso: marzo-2009
Mensajes: 74
Antigüedad: 15 años, 1 mes
Puntos: 0
Como modificar varios registros desde un formulario

Saludos nuevamente a todos los genios del foro, y agradezco la ayuda que siempre me han dado, cada día aprendo algo nuevo de ustedes, solo que ahora por mas que busco no se como puedo hacer un update de varios registros desde un formulario, no se exactamente cual es el procedimiento ya que logro enviar el formulario actualizando de uno en uno pero cuando quiero que sean todos no se envia, solo se actualiza la pagina.

Solo quisiera que al enviar el formulario activando o desactivando la casilla en diferentes registros y que se actualicen todos los que modifiqué

Este es el codigo para que se ejecute al enviar el formulario:
Código HTML:
if (isset($_POST["enviar"])) {

$id= $_GET['id'];

if($_POST["activar"]=="si"){
$sql_update=mysql_query("UPDATE registros SET activo='no' WHERE id='$id'",$con) or
  die("Problemas en el select:".mysql_error());  }
elseif($_POST["activar"]=="no"){
$sql_update=mysql_query("UPDATE registros SET activo='no' WHERE id='$id'",$con) or
  die("Problemas en el select:".mysql_error());  }
}
El formulario es el siguiente en donde se imprimen correctamente todos los registros:
Código HTML:
 <div align="center">
              <center>
            <table border="2" width="48%" height="37" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#800000">
              <tr>
                <td width="15%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
                <b><font face="Arial Narrow" size="2">&nbsp;Id:</font></b></td>
                <td width="6%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
                <p align="center">
                <b><font face="Arial Narrow" size="2">Activo:</font></b></td>
                <td width="7%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
                <b><font face="Arial Narrow" size="2">Activar:</font></b></td>
                <td width="9%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
                <b><font face="Arial Narrow" size="2">Desactivar:</font></b></td>
              </tr>
<?                    
// Imprimiendo los resultados
while($array = mysql_fetch_array($cad)) {
   $id=$array['id'];
   $activ=$array['activo'];

if ( $activ == "" || $activ == "no"  ) { 
$activo2 = "No";}
else{
$activo2 = "Sí";}
   
?>
<form name="f1" method="post" action="?id=<? echo $id ?>">
              <tr>
                <td width="15%" height="6" bgcolor="#800000">
                <span style="font-size: 3pt">&nbsp;&nbsp; </span></td>
                <td width="6%" height="6" bgcolor="#800000">
                <span style="font-size: 3pt">&nbsp;</span></td>
                <td width="7%" height="6" bgcolor="#800000">
                <span style="font-size: 3pt">&nbsp;</span></td>
                <td width="9%" height="6" bgcolor="#800000">
                <span style="font-size: 3pt">&nbsp;</span></td>
              </tr>
              <tr>
                <td width="15%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
                <p align="center"><b><font size="2" face="Arial Narrow"><? echo $id ?>&nbsp;</font></b></td>
                <td width="6%" height="27"  style="border: 2px outset #000080" bgcolor="#FFFFFF">
                <p align="center"><b><font size="2" face="Arial Narrow"><? echo $activo2 ?>&nbsp;</font></b></td>
                <td width="7%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
                <p align="center"><input type="radio" name="activar" value="si"></td>
                <td width="9%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
                <p align="center"><input type="radio" name="activar" value="no"></td>
              </tr>
               <tr>
                <td width="37%" height="37" colspan="4">
                <p align="center">
                <span style="font-size: 3pt"><input type="submit" value="Enviar" name="enviar" style="font-family: Arial Narrow; font-size: 10pt; font-weight: bold"></form></td>
              </tr>
              <?
}
$con=mysql_close($con);
?>
              
              </table>
              </center>
            </div> 
El problema es que me sale un boton de enviar para cada registro y actualiza los registros de uno en uno, si bajo el botón de enviar para actualizar todos los registros con un solo boton no funciona.

Porfis no se como hacerle, alguien me puede hechar una manita... si?

De antemano muchas gracias...
  #2 (permalink)  
Antiguo 11/12/2009, 14:59
Avatar de jackson666  
Fecha de Ingreso: noviembre-2009
Ubicación: Buenos Aires, Argentina
Mensajes: 1.971
Antigüedad: 14 años, 5 meses
Puntos: 65
Respuesta: Como modificar varios registros desde un formulario

Disculpame pero no entiendo bien que es lo que necesitas....

Queres hacer un update que afecte varias filas en tu tabla mediante un formulario???
  #3 (permalink)  
Antiguo 11/12/2009, 15:02
Avatar de urgido  
Fecha de Ingreso: febrero-2005
Mensajes: 2.351
Antigüedad: 19 años, 2 meses
Puntos: 25
Respuesta: Como modificar varios registros desde un formulario

quitale la condición WHERE id='$id' por que ahí especificas que id va a actualizar más no que actualice todos, a forma que quede:

if($_POST["activar"]=="si"){
$sql_update=mysql_query("UPDATE registros SET activo='si' WHERE activo='no'",$con) or
die("Problemas en el select:".mysql_error());
}elseif($_POST["activar"]=="no"){
$sql_update=mysql_query("UPDATE registros SET activo='no' WHERE id='si'",$con) or
die("Problemas en el select:".mysql_error()); }
}

NOTA: es a lo que yo he entendido... igual y entendí mal, si es así te pido que detalles. Saludos
__________________
Hospedaje Web al mejor costo!
  #4 (permalink)  
Antiguo 11/12/2009, 15:11
 
Fecha de Ingreso: marzo-2009
Mensajes: 74
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Como modificar varios registros desde un formulario

Cita:
Iniciado por jackson666 Ver Mensaje
Disculpame pero no entiendo bien que es lo que necesitas....

Queres hacer un update que afecte varias filas en tu tabla mediante un formulario???
Si exactamente eso, muchas gracias por responder.
  #5 (permalink)  
Antiguo 11/12/2009, 15:14
 
Fecha de Ingreso: marzo-2009
Mensajes: 74
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Como modificar varios registros desde un formulario

Cita:
Iniciado por urgido Ver Mensaje
quitale la condición WHERE id='$id' por que ahí especificas que id va a actualizar más no que actualice todos, a forma que quede:

if($_POST["activar"]=="si"){
$sql_update=mysql_query("UPDATE registros SET activo='si' WHERE activo='no'",$con) or
die("Problemas en el select:".mysql_error());
}elseif($_POST["activar"]=="no"){
$sql_update=mysql_query("UPDATE registros SET activo='no' WHERE id='si'",$con) or
die("Problemas en el select:".mysql_error()); }
}

NOTA: es a lo que yo he entendido... igual y entendí mal, si es así te pido que detalles. Saludos
Gracias por tu respuesta, voy a intentar lo que dices solo que en donde pongo boton de enviar ya que como lo puse me sale un boton para cada registro impreso y si lo bajo para que salga un solo boton para todos el formulario no se envia.

Gracias de antemano
  #6 (permalink)  
Antiguo 11/12/2009, 15:16
Avatar de jackson666  
Fecha de Ingreso: noviembre-2009
Ubicación: Buenos Aires, Argentina
Mensajes: 1.971
Antigüedad: 14 años, 5 meses
Puntos: 65
Respuesta: Como modificar varios registros desde un formulario

Y bueno, entonces en tu formulario deberias requerir como dato:

1) que se ingrese el nombre de usuario (por ejemplo) que es el que se repite en tu tabla
2) que se ingrese los nuevos valores a modificar
3) en tu script php que es la accion del formulario, preguntar por todos los campos que tengan ese usuario (ejemplo) y hacer el update
  #7 (permalink)  
Antiguo 11/12/2009, 15:19
Avatar de urgido  
Fecha de Ingreso: febrero-2005
Mensajes: 2.351
Antigüedad: 19 años, 2 meses
Puntos: 25
Respuesta: Como modificar varios registros desde un formulario

saca el boton submit del while...
__________________
Hospedaje Web al mejor costo!
  #8 (permalink)  
Antiguo 11/12/2009, 15:27
 
Fecha de Ingreso: marzo-2009
Mensajes: 74
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Como modificar varios registros desde un formulario

Cita:
Iniciado por cara_luna Ver Mensaje
Gracias por tu respuesta, voy a intentar lo que dices solo que en donde pongo boton de enviar ya que como lo puse me sale un boton para cada registro impreso y si lo bajo para que salga un solo boton para todos el formulario no se envia.

Gracias de antemano
Ya lo intente y si le quito el WHERE id='$id'

Actualiza todos en una sola selección por ejemplo todos los registros en no ó en si
  #9 (permalink)  
Antiguo 11/12/2009, 15:28
Avatar de urgido  
Fecha de Ingreso: febrero-2005
Mensajes: 2.351
Antigüedad: 19 años, 2 meses
Puntos: 25
Respuesta: Como modificar varios registros desde un formulario

yes, para lo que tú quieres entonces debes crearte un arreglo que te permita identificar cuales quieres cambiar y cuales no. Con foreach puedes manipular ese arreglo, sabes de lo que hablo?

Saludos
__________________
Hospedaje Web al mejor costo!
  #10 (permalink)  
Antiguo 11/12/2009, 15:29
 
Fecha de Ingreso: marzo-2009
Mensajes: 74
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Como modificar varios registros desde un formulario

Cita:
Iniciado por jackson666 Ver Mensaje
Y bueno, entonces en tu formulario deberias requerir como dato:

1) que se ingrese el nombre de usuario (por ejemplo) que es el que se repite en tu tabla
2) que se ingrese los nuevos valores a modificar
3) en tu script php que es la accion del formulario, preguntar por todos los campos que tengan ese usuario (ejemplo) y hacer el update
lo que pasa es que exactamente no se como hacer lo que dices, en realidad tengo la idea igual pero no el conocimiento, Gracias.
  #11 (permalink)  
Antiguo 11/12/2009, 15:31
 
Fecha de Ingreso: marzo-2009
Mensajes: 74
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Como modificar varios registros desde un formulario

Cita:
Iniciado por urgido Ver Mensaje
yes, para lo que tú quieres entonces debes crearte un arreglo que te permita identificar cuales quieres cambiar y cuales no. Con foreach puedes manipular ese arreglo, sabes de lo que hablo?

Saludos
perdon no se, un ejemplito pequeño???
  #12 (permalink)  
Antiguo 11/12/2009, 15:32
 
Fecha de Ingreso: marzo-2009
Mensajes: 74
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Como modificar varios registros desde un formulario

Cita:
Iniciado por urgido Ver Mensaje
saca el boton submit del while...
Si lo saco de while el formulario no se envía.
  #13 (permalink)  
Antiguo 11/12/2009, 15:33
Avatar de urgido  
Fecha de Ingreso: febrero-2005
Mensajes: 2.351
Antigüedad: 19 años, 2 meses
Puntos: 25
Respuesta: Como modificar varios registros desde un formulario

ya te respondí arriba, saludos
__________________
Hospedaje Web al mejor costo!
  #14 (permalink)  
Antiguo 11/12/2009, 15:34
 
Fecha de Ingreso: marzo-2009
Mensajes: 74
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Como modificar varios registros desde un formulario

Cita:
Iniciado por urgido Ver Mensaje
ya te respondí arriba, saludos
Bueno...de igual manera... Gracias
  #15 (permalink)  
Antiguo 11/12/2009, 15:35
Avatar de urgido  
Fecha de Ingreso: febrero-2005
Mensajes: 2.351
Antigüedad: 19 años, 2 meses
Puntos: 25
Respuesta: Como modificar varios registros desde un formulario

si sabes hacer el uso de arreglos y de foreach? Con eso se arregla el problema... si no sabes dimelo para seguirte ayudando aunque en www.php.net/foreach vienen ejemplos.
__________________
Hospedaje Web al mejor costo!
  #16 (permalink)  
Antiguo 11/12/2009, 15:38
 
Fecha de Ingreso: marzo-2009
Mensajes: 74
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Como modificar varios registros desde un formulario

Cita:
Iniciado por urgido Ver Mensaje
si sabes hacer el uso de arreglos y de foreach? Con eso se arregla el problema... si no sabes dimelo para seguirte ayudando aunque en www.php.net/foreach vienen ejemplos.
Muchisimas Gracias por todas tus respuestas voy a investigar en donde me indicas.

Saludos y mucha suerte.
  #17 (permalink)  
Antiguo 11/12/2009, 15:39
Avatar de jackson666  
Fecha de Ingreso: noviembre-2009
Ubicación: Buenos Aires, Argentina
Mensajes: 1.971
Antigüedad: 14 años, 5 meses
Puntos: 65
Respuesta: Como modificar varios registros desde un formulario

Código HTML:
<form action="update.php" method="post">
Ingrese su nombre
<br />
<input type="text" name="nombre" />
<br />

<!-- aca en vez de un select podes usar checkboxes para actualizar varios campos -->
<!-- si haces eso, tene en cuenta que deberias agregar tantos input text como checkboxes tengas -->

Seleccione campos a actualizar
<select name="campos">
<option selected="">Seleccione</option>
<option value="algo">Algo</option>
</select>
<br />
Ingrese nuevo dato:
<input type="text" name="cambio" />
<br />
<input type="submit" value="Enviar" />
</form> 
Y tu "update.php"

Código PHP:
<?php
$nombre
=$_POST['nombre'];
$campo=$_POST['campos'];
$cambio=$_POST['cambio'];

#haces todas las comprobaciones

$conectar=mysql_connect("localhost","root","");
$s=mysql_select_db("tuBaseDeDatos",$conectar);


$sql="update [tuTabla] set '$campo'='$cambio' where usuario='$nombre';";
$consulta=mysql_query($sql,$conectar);

#si queres imprimis algo en pantalla....

?>
  #18 (permalink)  
Antiguo 11/12/2009, 15:46
 
Fecha de Ingreso: marzo-2009
Mensajes: 74
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Como modificar varios registros desde un formulario

Muchisimas gracias por tu respuesta jackson666 voy a probarlo.

Saludos.
  #19 (permalink)  
Antiguo 11/12/2009, 15:46
Avatar de urgido  
Fecha de Ingreso: febrero-2005
Mensajes: 2.351
Antigüedad: 19 años, 2 meses
Puntos: 25
Respuesta: Como modificar varios registros desde un formulario

lo hice todo desordenado ando a las prisas, checalo y comentas

<?
if (isset($_POST["enviar"])) {

$ide[]=$_POST['id'];
$valor[]=$_POST['activar'];

foreach ($ide as $v) {
foreach ($valor as $v2) {
$sql_update=mysql_query("UPDATE registros SET activo='".$v2."' WHERE id='".$v."'",$con) or die("Problemas en el select:".mysql_error()); }
}
}

}

?>

<div align="center">
<center>
<table border="2" width="48%" height="37" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#800000">
<tr>
<td width="15%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<b><font face="Arial Narrow" size="2">&nbsp;Id:</font></b></td>
<td width="6%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<p align="center">
<b><font face="Arial Narrow" size="2">Activo:</font></b></td>
<td width="7%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<b><font face="Arial Narrow" size="2">Activar:</font></b></td>
<td width="9%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<b><font face="Arial Narrow" size="2">Desactivar:</font></b></td>
</tr>
<?
$i=0;
// Imprimiendo los resultados
while($array = mysql_fetch_array($cad)) {
$x=$i++;
$id=$array['id'];
$activ=$array['activo'];

if ( $activ == "" || $activ == "no" ) {
$activo2 = "No";}
else{
$activo2 = "Sí";}

?>
<form name="f1" method="post" action="<? echo $_SERVER['PHP_SELF'];?>">
<tr>
<td width="15%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;&nbsp; </span></td>
<td width="6%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;</span></td>
<td width="7%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;</span></td>
<td width="9%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;</span></td>
</tr>
<tr>
<td width="15%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
<p align="center"><b><font size="2" face="Arial Narrow"><? echo $id ?>&nbsp;</font></b></td>
<td width="6%" height="27" style="border: 2px outset #000080" bgcolor="#FFFFFF">
<p align="center"><b><font size="2" face="Arial Narrow"><? echo $activo2 ?>&nbsp;</font></b></td>
<td width="7%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
<p align="center"><input type="radio" name="activar" value="si"></td>
<td width="9%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
<p align="center"><input type="radio" name="activar" value="no"></td>
</tr>
<tr>
<td width="37%" height="37" colspan="4">
&nbsp;</td>
</tr>
<?
}
?>
<input type="text" name="id" value="<? echo $id; ?>" style="display:none" />
<tr><td><input type="submit" value="Enviar" name="enviar" style="font-family: Arial Narrow; font-size: 10pt; font-weight: bold"></form></td></tr>
<?
$con=mysql_close($con);
?>

</table>
</center>
</div>
__________________
Hospedaje Web al mejor costo!
  #20 (permalink)  
Antiguo 11/12/2009, 16:03
 
Fecha de Ingreso: marzo-2009
Mensajes: 74
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Como modificar varios registros desde un formulario

Muchisimas gracias urgido voy a probarlo.
  #21 (permalink)  
Antiguo 11/12/2009, 16:49
 
Fecha de Ingreso: marzo-2009
Mensajes: 74
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Como modificar varios registros desde un formulario


Última edición por cara_luna; 11/12/2009 a las 17:17
  #22 (permalink)  
Antiguo 11/12/2009, 17:15
 
Fecha de Ingreso: marzo-2009
Mensajes: 74
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Como modificar varios registros desde un formulario

Cita:
Iniciado por urgido Ver Mensaje
lo hice todo desordenado ando a las prisas, checalo y comentas

<?
if (isset($_POST["enviar"])) {

$ide[]=$_POST['id'];
$valor[]=$_POST['activar'];

foreach ($ide as $v) {
foreach ($valor as $v2) {
$sql_update=mysql_query("UPDATE registros SET activo='".$v2."' WHERE id='".$v."'",$con) or die("Problemas en el select:".mysql_error()); }
}
}

}

?>

<div align="center">
<center>
<table border="2" width="48%" height="37" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#800000">
<tr>
<td width="15%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<b><font face="Arial Narrow" size="2">&nbsp;Id:</font></b></td>
<td width="6%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<p align="center">
<b><font face="Arial Narrow" size="2">Activo:</font></b></td>
<td width="7%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<b><font face="Arial Narrow" size="2">Activar:</font></b></td>
<td width="9%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<b><font face="Arial Narrow" size="2">Desactivar:</font></b></td>
</tr>
<?
$i=0;
// Imprimiendo los resultados
while($array = mysql_fetch_array($cad)) {
$x=$i++;
$id=$array['id'];
$activ=$array['activo'];

if ( $activ == "" || $activ == "no" ) {
$activo2 = "No";}
else{
$activo2 = "Sí";}

?>
<form name="f1" method="post" action="<? echo $_SERVER['PHP_SELF'];?>">
<tr>
<td width="15%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;&nbsp; </span></td>
<td width="6%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;</span></td>
<td width="7%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;</span></td>
<td width="9%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;</span></td>
</tr>
<tr>
<td width="15%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
<p align="center"><b><font size="2" face="Arial Narrow"><? echo $id ?>&nbsp;</font></b></td>
<td width="6%" height="27" style="border: 2px outset #000080" bgcolor="#FFFFFF">
<p align="center"><b><font size="2" face="Arial Narrow"><? echo $activo2 ?>&nbsp;</font></b></td>
<td width="7%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
<p align="center"><input type="radio" name="activar" value="si"></td>
<td width="9%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
<p align="center"><input type="radio" name="activar" value="no"></td>
</tr>
<tr>
<td width="37%" height="37" colspan="4">
&nbsp;</td>
</tr>
<?
}
?>
<input type="text" name="id" value="<? echo $id; ?>" style="display:none" />
<tr><td><input type="submit" value="Enviar" name="enviar" style="font-family: Arial Narrow; font-size: 10pt; font-weight: bold"></form></td></tr>
<?
$con=mysql_close($con);
?>

</table>
</center>
</div>
Hola de nuevo urgido me apena mucho molestarte pero porfis a lo mejor es un pequeñito error, sabes si se envía pero solo modifica el último registro obtenido y al seleccionar una opcion se des-selecciona la del otro registro, mejor puse "checkbox" en lugar de "radio" y aunque no se desmarca la casilla solo se modifica el ultimo registro.

Ojalá me puedas contestar - de antemano muchisimas Gracias por tu tiempo.
  #23 (permalink)  
Antiguo 11/12/2009, 17:26
Avatar de urgido  
Fecha de Ingreso: febrero-2005
Mensajes: 2.351
Antigüedad: 19 años, 2 meses
Puntos: 25
Respuesta: Como modificar varios registros desde un formulario

mm dejame checar, saludos
__________________
Hospedaje Web al mejor costo!
  #24 (permalink)  
Antiguo 11/12/2009, 17:30
Avatar de urgido  
Fecha de Ingreso: febrero-2005
Mensajes: 2.351
Antigüedad: 19 años, 2 meses
Puntos: 25
Respuesta: Como modificar varios registros desde un formulario

<?
if (isset($_POST["enviar"])) {

$ide[]=$_POST['id'];
$valor[]=$_POST['activar'];

foreach ($ide as $v) {
foreach ($valor as $v2) {
$sql_update=mysql_query("UPDATE registros SET activo='".$v2."' WHERE id='".$v."'",$con) or die("Problemas en el select:".mysql_error()); }
}
}

}

?>

<div align="center">
<center>
<table border="2" width="48%" height="37" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#800000">
<tr>
<td width="15%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<b><font face="Arial Narrow" size="2">&nbsp;Id:</font></b></td>
<td width="6%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<p align="center">
<b><font face="Arial Narrow" size="2">Activo:</font></b></td>
<td width="7%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<b><font face="Arial Narrow" size="2">Activar:</font></b></td>
<td width="9%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<b><font face="Arial Narrow" size="2">Desactivar:</font></b></td>
</tr>
<?
$i=0;
// Imprimiendo los resultados
while($array = mysql_fetch_array($cad)) {
$x=$i++;
$id=$array['id'];
$activ=$array['activo'];

if ( $activ == "" || $activ == "no" ) {
$activo2 = "No";}
else{
$activo2 = "Sí";}

?>
<form name="f1" method="post" action="<? echo $_SERVER['PHP_SELF'];?>">
<tr>
<td width="15%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;&nbsp; </span></td>
<td width="6%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;</span></td>
<td width="7%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;</span></td>
<td width="9%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;</span></td>
</tr>
<tr>
<td width="15%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
<p align="center"><b><font size="2" face="Arial Narrow"><? echo $id ?>&nbsp;</font></b></td>
<td width="6%" height="27" style="border: 2px outset #000080" bgcolor="#FFFFFF">
<p align="center"><b><font size="2" face="Arial Narrow"><? echo $activo2 ?>&nbsp;</font></b></td>
<td width="7%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
<p align="center"><input type="radio" name="activar" value="si"></td>
<td width="9%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
<p align="center"><input type="radio" name="activar" value="no"></td>
</tr>
<tr>
<td width="37%" height="37" colspan="4">
&nbsp;</td>
</tr>
<input type="text" name="id" value="<? echo $id; ?>" style="display:none" />
<?
}
?>

<tr><td><input type="submit" value="Enviar" name="enviar" style="font-family: Arial Narrow; font-size: 10pt; font-weight: bold"></form></td></tr>
<?
$con=mysql_close($con);
?>

</table>
</center>
</div>
__________________
Hospedaje Web al mejor costo!
  #25 (permalink)  
Antiguo 11/12/2009, 18:48
 
Fecha de Ingreso: marzo-2009
Mensajes: 74
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Como modificar varios registros desde un formulario

Cita:
Iniciado por urgido Ver Mensaje
<?
if (isset($_POST["enviar"])) {

$ide[]=$_POST['id'];
$valor[]=$_POST['activar'];

foreach ($ide as $v) {
foreach ($valor as $v2) {
$sql_update=mysql_query("UPDATE registros SET activo='".$v2."' WHERE id='".$v."'",$con) or die("Problemas en el select:".mysql_error()); }
}
}

}

?>

<div align="center">
<center>
<table border="2" width="48%" height="37" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#800000">
<tr>
<td width="15%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<b><font face="Arial Narrow" size="2">&nbsp;Id:</font></b></td>
<td width="6%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<p align="center">
<b><font face="Arial Narrow" size="2">Activo:</font></b></td>
<td width="7%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<b><font face="Arial Narrow" size="2">Activar:</font></b></td>
<td width="9%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<b><font face="Arial Narrow" size="2">Desactivar:</font></b></td>
</tr>
<?
$i=0;
// Imprimiendo los resultados
while($array = mysql_fetch_array($cad)) {
$x=$i++;
$id=$array['id'];
$activ=$array['activo'];

if ( $activ == "" || $activ == "no" ) {
$activo2 = "No";}
else{
$activo2 = "Sí";}

?>
<form name="f1" method="post" action="<? echo $_SERVER['PHP_SELF'];?>">
<tr>
<td width="15%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;&nbsp; </span></td>
<td width="6%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;</span></td>
<td width="7%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;</span></td>
<td width="9%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;</span></td>
</tr>
<tr>
<td width="15%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
<p align="center"><b><font size="2" face="Arial Narrow"><? echo $id ?>&nbsp;</font></b></td>
<td width="6%" height="27" style="border: 2px outset #000080" bgcolor="#FFFFFF">
<p align="center"><b><font size="2" face="Arial Narrow"><? echo $activo2 ?>&nbsp;</font></b></td>
<td width="7%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
<p align="center"><input type="radio" name="activar" value="si"></td>
<td width="9%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
<p align="center"><input type="radio" name="activar" value="no"></td>
</tr>
<tr>
<td width="37%" height="37" colspan="4">
&nbsp;</td>
</tr>
<input type="text" name="id" value="<? echo $id; ?>" style="display:none" />
<?
}
?>

<tr><td><input type="submit" value="Enviar" name="enviar" style="font-family: Arial Narrow; font-size: 10pt; font-weight: bold"></form></td></tr>
<?
$con=mysql_close($con);
?>

</table>
</center>
</div>
Gracias por responder, sabes sigue igual solo cambia el ultimo registro.

Al parecer va a ser un poco más complicado de lo que pensé.

Saludos y mchisimas gracias por todas tus atenciones.
  #26 (permalink)  
Antiguo 11/12/2009, 18:52
Avatar de urgido  
Fecha de Ingreso: febrero-2005
Mensajes: 2.351
Antigüedad: 19 años, 2 meses
Puntos: 25
Respuesta: Como modificar varios registros desde un formulario

<?
if (isset($_POST["enviar"])) {

$ide[]=$_POST['id'];
$valor[]=$_POST['activar'];

$total=count($ide);
foreach ($ide as $v){
foreach ($valor as $v2){

for ($i=1; $i<=$total; $i++) {
$sql_update=mysql_query("UPDATE registros SET activo='".$v2."' WHERE id='".$v."'",$con) or die("Problemas en el select:".mysql_error()); }
}
}
}

}

?>


prueba cone se code en lugar del que te mande... lo de <? ?>
__________________
Hospedaje Web al mejor costo!
  #27 (permalink)  
Antiguo 11/12/2009, 19:18
 
Fecha de Ingreso: marzo-2009
Mensajes: 74
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Como modificar varios registros desde un formulario

no funciona y subí y baje del while el codigo:

<input type="text" name="id" value="<? echo $id; ?>" style="display:none" />

y nada, solo cambia el último registro, igualmente muchisimas gracias, la verdad ya me mucha pena contigo, te estoy quitando mucho tiempo. si quieres en otro momento lo seguimos intentando.

Saludos.
  #28 (permalink)  
Antiguo 11/12/2009, 19:19
Avatar de urgido  
Fecha de Ingreso: febrero-2005
Mensajes: 2.351
Antigüedad: 19 años, 2 meses
Puntos: 25
Respuesta: Como modificar varios registros desde un formulario

no estoy carburando, ando ocupadisisisiimo ... en cuanto me deoscupe le doy hilo sino la ayuda que te den será bien recibida, saludos
__________________
Hospedaje Web al mejor costo!
  #29 (permalink)  
Antiguo 11/12/2009, 19:30
 
Fecha de Ingreso: marzo-2009
Mensajes: 74
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Como modificar varios registros desde un formulario

Cita:
Iniciado por urgido Ver Mensaje
no estoy carburando, ando ocupadisisisiimo ... en cuanto me deoscupe le doy hilo sino la ayuda que te den será bien recibida, saludos
Por supuesto muchisimas gracias.
  #30 (permalink)  
Antiguo 11/12/2009, 19:43
Avatar de urgido  
Fecha de Ingreso: febrero-2005
Mensajes: 2.351
Antigüedad: 19 años, 2 meses
Puntos: 25
Respuesta: Como modificar varios registros desde un formulario

último intento hahaha

<?
if (isset($_POST["enviar"])) {

$count=count($_POST['id']);
for($i=0;$i<$count;$i++){
$sql_update=mysql_query("UPDATE registros SET activo='".$_POST['activar'][$i]."' WHERE id='".$_POST['id'][$i]."'",$con) or die("Problemas en el select:".mysql_error()); }
}
}


?>


<div align="center">
<center>
<table border="2" width="48%" height="37" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#800000">
<tr>
<td width="15%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<b><font face="Arial Narrow" size="2">&nbsp;Id:</font></b></td>
<td width="6%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<p align="center">
<b><font face="Arial Narrow" size="2">Activo:</font></b></td>
<td width="7%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<b><font face="Arial Narrow" size="2">Activar:</font></b></td>
<td width="9%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<b><font face="Arial Narrow" size="2">Desactivar:</font></b></td>
</tr>
<?
// Imprimiendo los resultados
while($array = mysql_fetch_array($cad)) {
$id=$array['id'];
$activ=$array['activo'];

if ( $activ == "" || $activ == "no" ) {
$activo2 = "No";}
else{
$activo2 = "Sí";}

?>
<form name="f1" method="post" action="<? echo $_SERVER['PHP_SELF'];?>">
<tr>
<td width="15%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;&nbsp; </span></td>
<td width="6%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;</span></td>
<td width="7%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;</span></td>
<td width="9%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;</span></td>
</tr>
<tr>
<td width="15%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
<p align="center"><b><font size="2" face="Arial Narrow"><? echo $id; ?>&nbsp;</font></b></td>
<td width="6%" height="27" style="border: 2px outset #000080" bgcolor="#FFFFFF">
<p align="center"><b><font size="2" face="Arial Narrow"><? echo $activo2; ?>&nbsp;</font></b></td>
<td width="7%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
<p align="center"><input type="radio" name="activar[]" value="si"></td>
<td width="9%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
<p align="center"><input type="radio" name="activar[]" value="no"></td>
</tr>
<tr>
<td width="37%" height="37" colspan="4">
&nbsp;</td>
</tr>
<input type="text" name="id[]" value="<? echo $id; ?>" style="display:none" />
<?
}
?>

<tr><td><input type="submit" value="Enviar" name="enviar" style="font-family: Arial Narrow; font-size: 10pt; font-weight: bold"></form></td></tr>
<?
$con=mysql_close($con);
?>

</table>
</center>
</div>
__________________
Hospedaje Web al mejor costo!
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:10.