Ver Mensaje Individual
  #3 (permalink)  
Antiguo 09/02/2016, 10:59
Amiancht
 
Fecha de Ingreso: mayo-2013
Mensajes: 169
Antigüedad: 11 años
Puntos: 25
Respuesta: eliminar varias filas con checkbox

Cita:
Iniciado por cher1_7 Ver Mensaje
Que tal amigos un saludos y buenos dias haber si me pueden ayudar

resulta que tengo un form con informacion de una BD, quiero poder eliminar filas con un checkbox pero solo consigo eliminar de 1 por 1 aunque seleccione todos los checkbox muestro el codigo

este es el formulario con el checkbox
Código PHP:
Ver original
  1. <form name="form1" method="post" action="eliminar_prog.php">
  2.   <table border=1 align="center" cellpadding="0" cellspacing="0" class="tabla" id="medium1">
  3.     <thead>
  4.       <tr>
  5.         <td width="149" height="24" id="titulo"><p>ELIMINAR PROGRAMA</p></td>
  6.         <td width="51" id="titulo">PISDTE</td>
  7.         <td width="35" id="titulo">PIORD</td>
  8.         <td width="48" id="titulo">PICNME</td>
  9.         <td width="40" id="titulo">PIDESC</td>
  10.         <td width="43" id="titulo">PIPROD</td>
  11.         <td width="42" id="titulo">PIOQTY</td>
  12.         <td width="53" id="titulo">PRIORITY</td>
  13.         <td width="51" id="titulo">ENTDATE</td>
  14.         <td width="67" id="titulo">COMMENTS</td>
  15.         <td width="30" id="titulo">AREA</td>
  16.         <td width="41" id="titulo">STATUS</td>
  17.         <td width="41" id="titulo">&nbsp;</td>
  18.       </tr>
  19.     <tbody>
  20.       <?php while($row=$resultado->fetch_assoc()){ ?>
  21.       <tr>
  22.         <td height="25"><a href="eliminar_prog.php?id=<?php echo $row['id'];?>">
  23.           <input name="id" type="checkbox" id="id" value="<?php echo $row['id']?>">
  24.         </a></td>
  25.         <td><?php echo $row['pisdte'];?></td>
  26.         <td><?php echo $row['piord'];?></td>
  27.         <td><?php echo $row['picnme'];?></td>
  28.         <td><?php echo $row['pidesc'];?></td>
  29.         <td><?php echo $row['piprod'];?></td>
  30.         <td><?php echo $row['pioqty']?></td>
  31.         <td><?php echo $row['priority']?></td>
  32.         <td><?php echo $row['entdate']?></td>
  33.         <td><?php echo $row['comments']?></td>
  34.         <td><?php echo $row['area']?></td>
  35.         <td><?php echo $row['status']?></td>
  36.         <td><label for="id"></label></td>
  37.       </tr>
  38.       <?php } ?>
  39.     </tbody>
  40.   </table>
  41.   <br>
  42.   <input type="submit" name="button" id="button" value="Eliminar Seleccionados">
  43. </form>

este es el que elimina eliminar_prog.php
Código PHP:
Ver original
  1. <?php
  2.    
  3.     require('conexion.php');
  4.    
  5.     $id=$_POST['id'];
  6.    
  7.     $query="DELETE FROM master_spcls WHERE id='$id'";
  8.    
  9.     $resultado=$mysqli->query($query);
  10.    
  11. ?>
Obviamente deberas pasar un array por post con todos los IDs de cada fila. Lo que has hecho solo funcionaria para una sola fila.

Para pasar un array por post, en el name del input debes poner en vez de "id" pon "id[]" con los corchetes.
Código HTML:
Ver original
  1. <input name="id[]" type="checkbox" id="id" value="<?php echo $row['id']?>">

Y luego cuando lo recojas, recorre el array con un foreach y los vas borrando.