Ver Mensaje Individual
  #5 (permalink)  
Antiguo 10/02/2007, 11:27
Garmauco
 
Fecha de Ingreso: mayo-2006
Mensajes: 99
Antigüedad: 18 años
Puntos: 0
Re: checkbox como en phpmyadmin

Holas.... bueno ya he encontrado la solucion,... ya esta el script listo .... ojala le sirva a alguien,.. ...



Código PHP:
<?php require_once('Conn.php'); 
$maxReg 10;
$Reg_ini 0;

mysql_select_db($database_Conn$Conn);
$sql "SELECT id_usuario, usuario,telefono FROM usuarios";
$sql_limit sprintf("%s LIMIT %d, %d"$sql$Reg_ini$maxReg);
$cursor mysql_query($sql_limit$Conn) or die(mysql_error());
$row mysql_fetch_assoc($cursor);

if (isset(
$_GET['totalRegs'])) {
  
$totalRegs $_GET['totalRegs'];
} else {
  
$all_Regs mysql_query($sql);
  
$totalRegsmysql_num_rows($all_Regs);
}
?>
<!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>
<title>Actualizacion con Checkbox</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="prueba.php">
  <?php do { ?>
    <table width="80%">
      <tr>
      <td width="40%" ><?php echo $row['usuario']; ?> </td>
      <td width="49%" ><?php echo $row['telefono']; ?> </td>
      <td width="11%" >
      <label>
      <input type="checkbox" name="reg[<?php echo $row['id_usuario']; ?>]" value="reg[<?php echo $row['id_usuario']; ?>]" />
      </label></td>
    </tr>
          </table>
    <?php } while ($rowmysql_fetch_assoc($cursor)); ?>
    <br />
    <label>
    <input type="submit" name="enviar" value="Enviar" >
        

    </label>
</form>
</body>
</html>
<?php
if ($_POST['enviar'] == "Enviar"){
if(!empty(
$_POST['reg'])) { 
echo
"....";
echo
"<form name=gudr method=POST action='prueba.php'>";
     
$registros array_keys($_POST['reg']); 
     
$registros implode("','"$registros);
     
$registros "'".$registros."'";
     
$sql1="SELECT * FROM usuarios WHERE id_usuario IN ($registros)";
    
$cursor1 mysql_query$sql1$Conn );
    
$j=mysql_num_fields($cursor1); 
    
$k=mysql_num_rows($cursor1);
    echo
$k;
    
$i=1;
    while( 
$fila mysql_fetch_array$cursor1 ) ) {
              
$campo[0] = $fila[0];
              
$campo[1] = $fila[1];
              
$campo[2] = $fila[2];         
              echo
$campo[1];
              echo
"<p>ID: ";
              echo
"<input type= text name=id$i size=20 value='$campo[0]'>";
              echo
"</p>";
              echo
"<p>Nombre: ";
              echo
"<input type= text name=nmb$i size=20 value='$campo[1]'>";
              echo
"</p>";
              echo
"<p>Telefono: ";
              echo
"<input type= text name=tel$i size=20 value='$campo[2]'>";
              echo
"</p>";    
              echo
"<HR size=1 align=right width=100% color=7D889A>";                        
     
$i++;
    }
echo
"<input type=submit name=guardar value=Guardar>";
echo
"</form>";

}
if (
$_POST['guardar'] == "Guardar"){
echo
"...";
echo
$k;
for (
$i=1$i <= 10$i++){
if (isset(
$_POST["id" $i])){ 
$id $_POST["id" $i];
$nmb $_POST["nmb" $i]; 
$tel $_POST["tel" $i]; 
$sql="UPDATE usuarios SET usuario = '$nmb', telefono= '$tel' WHERE id_usuario = $id";
          if (
mysql_query($sql))
            echo 
"<br>Datos actualizados con éxito";
         else
            echo 
"<br>Datos NO actualizados";
            echo
"<br>".$sql;  

}
}
mysql_free_result($cursor);
?>
__________________
El sabio puede sentarse en un hormiguero, pero sólo el necio se queda sentado en él