Ver Mensaje Individual
  #4 (permalink)  
Antiguo 18/04/2008, 08:52
tuky
Usuario no validado
 
Fecha de Ingreso: julio-2003
Ubicación: <?="www.tuky.cl";?>
Mensajes: 132
Antigüedad: 20 años, 9 meses
Puntos: 4
Re: Eliminar registro de una tabla con checkbox

Holaaa!!

Bueno, yo le he dado muchas vueltas a este asunto... ya que también necesitaba hacer algo parecido... espero te sirva, intenta entenderlo y por cualquier duda acá estamos para ayudar!

Código PHP:
<?php    
    $link 
mysql_connect("localhost""root""");
    
mysql_select_db("base_datos"$link);
    
    if (isset(
$_POST['eliminar_seleccion']))
        if (
count($_POST['seleccion']))
            foreach(
$_POST['seleccion'] as $id => $valor)
                
mysql_query("DELETE FROM tabla WHERE id = ".$id." LIMIT 1"$link);
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0" cellpadding="5">
  <tr>
    <td>ID</td>
    <td>Nombre</td>
    <td>Telefono</td>
    <td>&nbsp;</td>
  </tr>
<?php
    $result 
mysql_query("SELECT * FROM tabla"$link);
    while (
$row mysql_fetch_assoc($result)) {
?>
  <tr>
    <td><?php echo $row['id']; ?></td>
    <td><?php echo $row['nombre']; ?></td>
    <td><?php echo $row['telefono']; ?></td>
    <td><input type="checkbox" name="seleccion[<?php echo $row['id']; ?>]" /></td>
  </tr>
<?php
    
}
?>
</table>
<input name="eliminar_seleccion" type="submit" value="Eliminar Seleccion" />
</form>
la tabla ocupada en el ejemplo se crearía así:
Código:
create table tabla (
    id integer auto_increment,
    nombre varchar(50),
    telefono integer,
    primary key (id)
)