Re: using multiple checkboxes to delete from db

From: Date: Sat, 30 Mar 2002 23:38:17 +0000
Subject: Re: using multiple checkboxes to delete from db
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-18064@lists.php.net to get a copy of this message
to make it a little better, make one connection to the db before you loop and then close the connection [connect] foreach loop [close connect] olinux --- "wesley grubbs:." <wesley.grubbs@zg.tel.hr> wrote: > thanks guys for the aid. > > in the end, i went with creating a check box that > looks like this: > > <input type="checkbox" name="del[]" value="<?php > print($row[id]); ?>"> > > and the dirty work of deleting it looks like this:: > > foreach($_POST["del"] as $val) { > > $sql = "DELETE FROM $tablename WHERE id = $val"; > > ...connect to database.. run $sql.. close db.. yadda > yadda.. > > } > > i can do this on the same page... it's short and > pretty easy to follow. ... > oh .. and it works :) > > wes > > > > One way you could do this. Is have the form point > to itself i.e. > $PHP_SELF, > > then set a variable in the form if it is set when > the page loads the run > the > > form processing script. As for the delete > function one way to do it would > > be since you are holding the checkboxes in an > array. Do a while or a for > > loop doing the delete statement for each id. Like > the following code. > > > > for($i = 0; $i < count(chkBoxArray); $i++){ > > $sql = "DELETE FROM tblName WHERE tblID = > '$row[$i]'"; > > if(!sql_query($sql)){ > > echo "ERROR: ".mysql_query(); > > } > > } > > > > Or something of that sort. Hope it helps. > > > > -Mike > > mikede@soreye.com > > http://www.soreye.com > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > __________________________________________________ Do You Yahoo!? Yahoo! Greetings - send holiday greetings for Easter, Passover http://greetings.yahoo.com/

« previous php.db (#18064) next »