Re: using multiple checkboxes to delete from db

From: Date: Sat, 30 Mar 2002 23:33:27 +0000
Subject: Re: using multiple checkboxes to delete from db
References: 1 2 3  Groups: php.db 
Request: Send a blank email to php-db+get-18063@lists.php.net to get a copy of this message
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

« previous php.db (#18063) next »