<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://php.apsique.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>Php y otras yerbas - Como borrar múltiples registros con checkbox - Comentarios</title>
 <link>http://php.apsique.com/contenido/borrar_multiples_registros_con_checkbox</link>
 <description>Comentarios para &quot;Como borrar múltiples registros con checkbox&quot;</description>
 <language>es</language>
<item>
 <title>Necesito borrar el mismo id</title>
 <link>http://php.apsique.com/contenido/borrar_multiples_registros_con_checkbox#comment-80937</link>
 <description>&lt;p&gt;Necesito borrar el mismo id en dos tablas a la vez ya que están relacionadas, pero intente de la siguiente forma sin tener exito:&lt;/p&gt;
&lt;p&gt;$Lista=array_keys($_POST[&#039;campos&#039;]);&lt;br /&gt;
echo $sql=&quot;DELETE FROM app a, app_link l WHERE a.id_app IN (&quot;.implode(&#039;,&#039;,$Lista).&quot;) AND l.id_app IN (&quot;.implode(&#039;,&#039;,$Lista).&quot;)&quot;;&lt;br /&gt;
mysql_query($sql);&lt;/p&gt;
&lt;p&gt;igual probe otras formas sin tener exito.... la idea es hacerlo en una misma consulta y no tener que hacer una consulta por cada id que vaya a borrar...&lt;/p&gt;
&lt;p&gt;agradezco a quien me pueda dar una idea.&lt;/p&gt;
&lt;p&gt;y gracias por este ejm, me ha sido de gran utilidad... muy simple y practico, gracias.&lt;/p&gt;
</description>
 <pubDate>Mon, 05 May 2008 10:44:53 -0700</pubDate>
 <dc:creator>jefmaus</dc:creator>
 <guid isPermaLink="false">comment 80937 at http://php.apsique.com</guid>
</item>
<item>
 <title>No te entendí :S</title>
 <link>http://php.apsique.com/contenido/borrar_multiples_registros_con_checkbox#comment-79570</link>
 <description>&lt;p&gt;No te entendí :S&lt;/p&gt;
</description>
 <pubDate>Tue, 01 Apr 2008 13:23:43 -0700</pubDate>
 <dc:creator>clbustos</dc:creator>
 <guid isPermaLink="false">comment 79570 at http://php.apsique.com</guid>
</item>
<item>
 <title>Hola, estoy probando la</title>
 <link>http://php.apsique.com/contenido/borrar_multiples_registros_con_checkbox#comment-79569</link>
 <description>&lt;p&gt;Hola, estoy probando la rutina pero no funciona  quisiera saber si esta funciona para paginas recursivas&lt;/p&gt;
&lt;p&gt;gracias mariales&lt;/p&gt;
</description>
 <pubDate>Tue, 01 Apr 2008 11:44:02 -0700</pubDate>
 <dc:creator>mariales</dc:creator>
 <guid isPermaLink="false">comment 79569 at http://php.apsique.com</guid>
</item>
<item>
 <title>Muchas gracias por el</title>
 <link>http://php.apsique.com/contenido/borrar_multiples_registros_con_checkbox#comment-71269</link>
 <description>&lt;p&gt;Muchas gracias por el ejemplo dado, funciona excelente.&lt;/p&gt;
</description>
 <pubDate>Fri, 14 Dec 2007 07:05:53 -0800</pubDate>
 <dc:creator>villajohn</dc:creator>
 <guid isPermaLink="false">comment 71269 at http://php.apsique.com</guid>
</item>
<item>
 <title>no me sale el borrado no se</title>
 <link>http://php.apsique.com/contenido/borrar_multiples_registros_con_checkbox#comment-71220</link>
 <description>&lt;p&gt;no me sale el borrado no se en que estoy mal ya intente de todo ayuda por favor incluyo codgio que ocupo:&lt;br /&gt;
1.php&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
while ($row = mysql_fetch_row($result)){&lt;br /&gt;
	$id=$row[0];&lt;br /&gt;
	echo  \n;&lt;br /&gt;
	echo  \n;&lt;br /&gt;
   echo ;&lt;/p&gt;
&lt;p&gt;2.php&lt;br /&gt;
if(!empty($_POST[&#039;campos&#039;])) {&lt;br /&gt;
  $aLista=array_keys ($_POST[&#039;campos&#039;]);&lt;br /&gt;
  $sQuery=&quot;DELETE FROM temporal where id IN (&quot;.implode(&#039;,&#039;,$aLista).&quot;)&quot;;&lt;br /&gt;
  $resultado=mysql_query($sQuery,$db);&lt;br /&gt;
&lt;/code&gt;&lt;/p&gt;
</description>
 <pubDate>Mon, 10 Dec 2007 22:58:06 -0800</pubDate>
 <dc:creator>ALVARO</dc:creator>
 <guid isPermaLink="false">comment 71220 at http://php.apsique.com</guid>
</item>
<item>
 <title>no me sale el borrado no se</title>
 <link>http://php.apsique.com/contenido/borrar_multiples_registros_con_checkbox#comment-71219</link>
 <description>&lt;p&gt;no me sale el borrado no se en que estoy mal ya intente de todo ayuda por favor incluyo codgio que ocupo:&lt;br /&gt;
1.php&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
while ($row = mysql_fetch_row($result)){&lt;br /&gt;
	$id=$row[0];&lt;br /&gt;
	echo &quot;tr \n&quot;;&lt;br /&gt;
	echo &quot;td \n&quot;;&lt;br /&gt;
   echo &quot;input type=&#039;checkbox&#039; name=&#039;campos[$id]&#039;&quot;;&lt;/p&gt;
&lt;p&gt;2.php&lt;br /&gt;
if(!empty($_POST[&#039;campos&#039;])) {&lt;br /&gt;
  $aLista=array_keys ($_POST[&#039;campos&#039;]);&lt;br /&gt;
  $sQuery=&quot;DELETE FROM temporal where id IN (&quot;.implode(&#039;,&#039;,$aLista).&quot;)&quot;;&lt;br /&gt;
  $resultado=mysql_query($sQuery,$db);&lt;br /&gt;
&lt;/code&gt;&lt;/p&gt;
</description>
 <pubDate>Mon, 10 Dec 2007 22:56:24 -0800</pubDate>
 <dc:creator>Perejilillo desconocido</dc:creator>
 <guid isPermaLink="false">comment 71219 at http://php.apsique.com</guid>
</item>
<item>
 <title>Se te olvidó el punto</title>
 <link>http://php.apsique.com/contenido/borrar_multiples_registros_con_checkbox#comment-71211</link>
 <description>&lt;p&gt;Se te olvidó el punto después del paréntesis en &quot;$aLista)&quot;&lt;/p&gt;
</description>
 <pubDate>Mon, 10 Dec 2007 07:22:54 -0800</pubDate>
 <dc:creator>clbustos</dc:creator>
 <guid isPermaLink="false">comment 71211 at http://php.apsique.com</guid>
</item>
<item>
 <title>El codigo que se puso al</title>
 <link>http://php.apsique.com/contenido/borrar_multiples_registros_con_checkbox#comment-71206</link>
 <description>&lt;p&gt;El codigo que se puso al principio sobre los checkbox no hay forma que me corra, ya probe de todo pero nada.&lt;/p&gt;
&lt;p&gt;$sQuery=&quot;DELETE FROM usuarios WHERE user IN (&quot;.implode(&quot;,&quot;,$aLista)&quot;)&quot;;	&lt;/p&gt;
&lt;p&gt;y me da este error&lt;/p&gt;
&lt;p&gt;Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\Documents and Settings\Docencia\Desktop\server2go\htdocs\sdf\ejemplo que hice\elimina.php on line 15&lt;/p&gt;
</description>
 <pubDate>Sun, 09 Dec 2007 22:31:57 -0800</pubDate>
 <dc:creator>Adrian</dc:creator>
 <guid isPermaLink="false">comment 71206 at http://php.apsique.com</guid>
</item>
<item>
 <title>Estuve leyendo la solucion</title>
 <link>http://php.apsique.com/contenido/borrar_multiples_registros_con_checkbox#comment-71142</link>
 <description>&lt;p&gt;Estuve leyendo la solucion para Borrar múltiples registros con checkbox, es muy interesante....&lt;/p&gt;
&lt;p&gt;Quiero AGREGAR MULTIPLES REGISTROS :&lt;/p&gt;
&lt;p&gt;Tengo una Tabla A&lt;br /&gt;
Tengo una Tabla B&lt;/p&gt;
&lt;p&gt;1) CON CHECKBOX (Agregar los ID que YO seleccione de la Tabla B y grabarlos en mi Tabla A)&lt;/p&gt;
&lt;p&gt;2) HACIENDO UN SELECT * FROM TABLA. (Agregar todos los registros de la Tabla B y grabarlos en mi Tabla A)&lt;/p&gt;
&lt;p&gt;Te agradecería si me orientaras como hacerlo... o una url o tutorial.&lt;/p&gt;
&lt;p&gt;Gracias de antemano&lt;/p&gt;
&lt;p&gt;Saludos&lt;/p&gt;
</description>
 <pubDate>Wed, 05 Dec 2007 14:18:31 -0800</pubDate>
 <dc:creator>Humberto</dc:creator>
 <guid isPermaLink="false">comment 71142 at http://php.apsique.com</guid>
</item>
<item>
 <title>Buenas noches internautas,</title>
 <link>http://php.apsique.com/contenido/borrar_multiples_registros_con_checkbox#comment-70706</link>
 <description>&lt;p&gt;Buenas noches internautas, mi pregunta es la siguiente alguno de ustedes tiene de casualidad algun ejemplo para la subida de varias fotografias a una tabla en una base de datos, de se asi me gustaria ver si me pueden facilar una explicacion de como hacerlo, yo tambien soy novel en la parte de programacion y estoy en un proyecto personal y requiero conocer como realizar esa parte. Muchas gracias de antemano por la ayuda que me puedan brindar.&lt;/p&gt;
</description>
 <pubDate>Mon, 29 Oct 2007 20:46:43 -0700</pubDate>
 <dc:creator>walter zeledon</dc:creator>
 <guid isPermaLink="false">comment 70706 at http://php.apsique.com</guid>
</item>
<item>
 <title>como puedo desplegar en la</title>
 <link>http://php.apsique.com/contenido/borrar_multiples_registros_con_checkbox#comment-70643</link>
 <description>&lt;p&gt;como puedo desplegar en la lista q jalo de la base de datos los checboxs&lt;br /&gt;
un ejemplo tengo en la base de datos paco juan y luis&lt;br /&gt;
y quiero desplegar&lt;br /&gt;
para cada nombre un checkbox&lt;br /&gt;
no se si me explico bien....&lt;/p&gt;
</description>
 <pubDate>Fri, 26 Oct 2007 18:56:44 -0700</pubDate>
 <dc:creator>Salvador Carrillo</dc:creator>
 <guid isPermaLink="false">comment 70643 at http://php.apsique.com</guid>
</item>
<item>
 <title>bien... cuando haces el</title>
 <link>http://php.apsique.com/contenido/borrar_multiples_registros_con_checkbox#comment-70613</link>
 <description>&lt;p&gt;bien... cuando haces el vinculo haces articulo.php?id=1 luego en el archivo articulo articulo.php haces una consulta en la BD para saber las imagenes asociadas a este texto y la muestras(por ejemplo con imageJPEG) cabe destacar que debes hacer una tabla que se cargue con el nombre de imagen que se llame por ej. imagenes donde tenga dos campos uno el nombre de la imagen y otro el id del articulo con el que la imagen esta asociada, esta tabla se llena en el formulario que subes las imagenes.&lt;br /&gt;
Cualquier cosa no dudes en consultarme.&lt;/p&gt;
</description>
 <pubDate>Wed, 24 Oct 2007 11:40:19 -0700</pubDate>
 <dc:creator>Perejilillo desconocido</dc:creator>
 <guid isPermaLink="false">comment 70613 at http://php.apsique.com</guid>
</item>
<item>
 <title>Fijate de tener todos los</title>
 <link>http://php.apsique.com/contenido/borrar_multiples_registros_con_checkbox#comment-70612</link>
 <description>&lt;p&gt;Fijate de tener todos los objetos dentro de un form de otra forma no podras reconocer el $_POST[eliminar]&lt;br /&gt;
es decir las declaraciones que hagas de  y el  tienen que estar dentro de un   dentro del formulario se reconocen los objetos si no de otra manera cuando hagas if($_POST[eliminar]) no te lo va a tomar. Espero que te sirva cualquier cosa no dudes en responderme.&lt;/p&gt;
</description>
 <pubDate>Wed, 24 Oct 2007 11:35:39 -0700</pubDate>
 <dc:creator>Perejilillo desconocido</dc:creator>
 <guid isPermaLink="false">comment 70612 at http://php.apsique.com</guid>
</item>
<item>
 <title>buenisimo la mejor el la</title>
 <link>http://php.apsique.com/contenido/borrar_multiples_registros_con_checkbox#comment-70538</link>
 <description>&lt;p&gt;buenisimo la mejor el la primer opcion no falla...&lt;/p&gt;
</description>
 <pubDate>Mon, 08 Oct 2007 10:05:06 -0700</pubDate>
 <dc:creator>Perejilillo desconocido</dc:creator>
 <guid isPermaLink="false">comment 70538 at http://php.apsique.com</guid>
</item>
<item>
 <title>Muy interesante, me parece</title>
 <link>http://php.apsique.com/contenido/borrar_multiples_registros_con_checkbox#comment-70485</link>
 <description>&lt;p&gt;Muy interesante, me parece excelente que ayudes a las personas,&lt;br /&gt;
mira tengo un pequeño problema, quiero poner imagenes que recojo desde la base de datos en un popup ?, o sea como pasarle la imagen a un popup desde la base de datos?&lt;br /&gt;
espero su respuesta&lt;br /&gt;
de antemano gracias&lt;/p&gt;
</description>
 <pubDate>Mon, 01 Oct 2007 11:45:36 -0700</pubDate>
 <dc:creator>Perejilillo desconocido</dc:creator>
 <guid isPermaLink="false">comment 70485 at http://php.apsique.com</guid>
</item>
<item>
 <title>Como borrar múltiples registros con checkbox</title>
 <link>http://php.apsique.com/contenido/borrar_multiples_registros_con_checkbox</link>
 <description>&lt;p&gt;Este último tiempo, un simpático chico argentino se ha vuelto cliente habitual de mi MSN. Me acaba de codeguntar como eliminar múltiples campos de una base de datos vía checkbox. Es una interesante consulta, así que les daré una breve explicación de las diversas formas de hacerlo.&lt;/p&gt;
&lt;!--break--&gt;
&lt;p&gt;
Primero, se deben codeparar los campos de manera adecuada. Para ello, hay dos formas.&lt;/p&gt;
&lt;p&gt;La que ocupo yo, por sanidad mental, es la siguiente&lt;/p&gt;
&lt;div class=&#039;code&#039;&gt;&lt;div class=&quot;hl-main&quot;&gt;&lt;ol class=&quot;hl-main&quot;&gt;&lt;li&gt;&amp;nbsp;&lt;span class=&quot;hl-brackets&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&#039;&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;checkbox&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&#039; &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&#039;&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;campos&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;[$&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;]&#039;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Donde $id es el valor del id para la tupla que queremos borrar. Si enviamos por post, la función php que recibe debe ser similar a la siguiente&lt;/p&gt;
&lt;div class=&#039;code&#039;&gt;&lt;div class=&quot;hl-main&quot;&gt;&lt;ol class=&quot;hl-main&quot;&gt;&lt;li&gt;&amp;nbsp;&lt;span class=&quot;hl-inlinetags&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;empty&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;campos&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;    &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$aLista&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;array_keys&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;campos&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;    &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$sQuery&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;DELETE FROM tabla where id IN (&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;implode&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$aLista&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;?&amp;gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Esa es la forma más simple. Una de las cosas que me molestan mucho de las aplicaciones que he visto es que casi nadie se molesta en usar el IN. Esta instrucción les permite seleccionar 1 o más valores para un campo, con un mínimo de utilización de recursos. La forma ineficiente sería&lt;/p&gt;
&lt;div class=&#039;code&#039;&gt;&lt;div class=&quot;hl-main&quot;&gt;&lt;ol class=&quot;hl-main&quot;&gt;&lt;li&gt;&amp;nbsp;&lt;span class=&quot;hl-inlinetags&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;empty&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;campos&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;    &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$aLista&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;array_keys&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;campos&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;    &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;foreach&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$aLista&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$iId&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;    &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$sQuery&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;DELETE FROM tabla where id=&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$iId&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-inlinetags&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;¿Por qué es mala esta última forma? Porque para cada campo borrado, se debe realizar una nueva conexión a la base de datos. Usando IN, el sistema de base de datos busca de forma muy rápida en la tabla que valores debe borrar y podemos obtener un aumento de rendimiento de 100% o más!
&lt;/p&gt;
&lt;p&gt;Ahora, la segunda forma:&lt;/p&gt;
&lt;p&gt;Para esto, debemos usar en los valores de los checkbox&lt;/p&gt;
&lt;div class=&#039;code&#039;&gt;&lt;div class=&quot;hl-main&quot;&gt;&lt;ol class=&quot;hl-main&quot;&gt;&lt;li&gt;&amp;nbsp;&lt;span class=&quot;hl-brackets&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&#039;&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;checkbox&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&#039; &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&#039;&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;campos&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;[]&#039; &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&#039;$&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Donde $id es el valor del id para la tupla que queremos borrar. La función php queda así&lt;/p&gt;
&lt;div class=&#039;code&#039;&gt;&lt;div class=&quot;hl-main&quot;&gt;&lt;ol class=&quot;hl-main&quot;&gt;&lt;li&gt;&amp;nbsp;&lt;span class=&quot;hl-inlinetags&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;empty&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;campos&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;    &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$aLista&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;campos&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;    &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$sQuery&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;DELETE FROM tabla where id IN (&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;hl-identifier&quot;&gt;implode&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;$aLista&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-string&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl-quotes&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hl-inlinetags&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ustedes dirán que esta forma es más sencilla. Claro, pero no es genérica. La primera forma nos permite incorporar varios valores de variable en el mismo input. Por ejemplo, valores de codeferencia distintos para varios usuarios
&lt;div class=&#039;code&#039;&gt;&lt;div class=&quot;hl-main&quot;&gt;&lt;ol class=&quot;hl-main&quot;&gt;&lt;li&gt;&amp;nbsp;&lt;span class=&quot;hl-brackets&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&#039;&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;checkbox&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&#039; &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&#039;&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;campos&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;[$&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;id_usuario&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;][$&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;id_codeferencia&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;]&#039;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;
Cosa que de la segunda forma quedaría
&lt;div class=&#039;code&#039;&gt;&lt;div class=&quot;hl-main&quot;&gt;&lt;ol class=&quot;hl-main&quot;&gt;&lt;li&gt;&amp;nbsp;&lt;span class=&quot;hl-brackets&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;hl-reserved&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&#039;&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;checkbox&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&#039; &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&#039;&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;campos&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;[$&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;id_usuario&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;][]&#039; &lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;=&#039;$&lt;/span&gt;&lt;span class=&quot;hl-var&quot;&gt;id_codeferencia&lt;/span&gt;&lt;span class=&quot;hl-code&quot;&gt;&#039;&lt;/span&gt;&lt;span class=&quot;hl-brackets&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Lo cual, a mi entender, no es tan bonito.&lt;/p&gt;

&lt;p&gt;Nos vemos!&lt;/p&gt;</description>
 <comments>http://php.apsique.com/contenido/borrar_multiples_registros_con_checkbox#comments</comments>
 <category domain="http://php.apsique.com/lenguajes/php/dummies">Php para dummies</category>
 <category domain="http://php.apsique.com/lenguajes/sql">SQL</category>
 <pubDate>Sun, 13 Feb 2005 18:09:29 -0800</pubDate>
 <dc:creator>clbustos</dc:creator>
 <guid isPermaLink="false">383 at http://php.apsique.com</guid>
</item>
</channel>
</rss>
