Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/03/2011, 14:59
lliwred
 
Fecha de Ingreso: marzo-2011
Mensajes: 3
Antigüedad: 13 años, 1 mes
Puntos: 0
como actualizo varios registros a la vez con checkbox

Saludos amigos espero me puedan ayudar el problema es que tengo una tabla que se llena dinámicamente de la bd las filas son los registros y cada uno tiene un checkbox con los siguientes campos idUsuario , usuario y dirección esta ultima esta en un tex tarea lo que necesito es poder actualizar las direcciones de los registros con checkbox seleccionados pero no se como hacerlo de antemano graciass

yo intente hacer esto
<?php
if ($_POST[actualizar]) {
conectar();
$direccion=$_POST['direccion'];
$lista=implode(',',$_POST['seleccionado']);
mysql_query("UPDATE usuario SET direccion='$direccion' WHERE idUsuario IN(".$lista.")");


} ?>
pero claro cuando entra en el while de la tabla toma el valor del ultimo registro y actualiza todos con el mismo

este es el codigo de la tabla:

<?php require_once('../Connections/conexion.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$maxRows_usuario = 10;
$pageNum_usuario = 0;
if (isset($_GET['pageNum_usuario'])) {
$pageNum_usuario = $_GET['pageNum_usuario'];
}
$startRow_usuario = $pageNum_usuario * $maxRows_usuario;

mysql_select_db($database_conexion, $conexion);
$query_usuario = "SELECT idUsuario, usuario,direccion FROM usuario";
$query_limit_usuario = sprintf("%s LIMIT %d, %d", $query_usuario, $startRow_usuario, $maxRows_usuario);
$usuario = mysql_query($query_limit_usuario, $conexion) or die(mysql_error());
$row_usuario = mysql_fetch_assoc($usuario);

if (isset($_GET['totalRows_usuario'])) {
$totalRows_usuario = $_GET['totalRows_usuario'];
} else {
$all_usuario = mysql_query($query_usuario);
$totalRows_usuario = mysql_num_rows($all_usuario);
}
$totalPages_usuario = ceil($totalRows_usuario/$maxRows_usuario)-1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<style type="text/css">
#form1 p {
text-align: center;
}
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="actualizar.php">
<table border="1">
<tr>
<td>&nbsp;</td>
<td>idusuario</td>
<td>usuario</td>
<td>direccion</td>
</tr>
<?php do { ?>
<tr>
<td><input type="checkbox" name="seleccionado[]" id="seleccionado[]" value="<?php echo $row_usuario['idUsuario']; ?>" /></td>
<td><?php echo $row_usuario['idUsuario']; ?></td>
<td><?php echo $row_usuario['usuario']; ?></td>
<td>
<textarea name="direccion" id="direccion" cols="45" rows="5"><?php echo $row_usuario['direccion']; ?></textarea></td>
</tr></MM:DECORATION></MM_REPEATEDREGION>
</table>
<table border="1">
<MM_REPEATEDREGION SOURCE="@@rs@@"><MM:DECORATION OUTLINE="Repetir" OUTLINEID=1>
<?php } while ($row_usuario = mysql_fetch_assoc($usuario)); ?>
</table>
<p>
<input type="submit" name="actualizar" id="actualizar" value="Actualizar" />
</p>
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($usuario);
?>