Re: using multiple checkboxes to delete from db
| From: | Mike de Libero | Date: | Sat, 30 Mar 2002 15:22:18 +0000 |
| Subject: | Re: using multiple checkboxes to delete from db | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-18059@lists.php.net to get a copy of this message | ||
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
----- Original Message -----
From: "wesley grubbs:." <wesley.grubbs@zg.tel.hr>
To: <php-db@lists.php.net>
Sent: Saturday, March 30, 2002 4:58 AM
Subject: [PHP-DB] using multiple checkboxes to delete from db
> i've been playing half the day with trying to get php to delete rows when
a
> checkbox is checked.
>
> i have a page that pulls all the data from db in a table. one row contains
> checkboxes. i want it so that whereever a checkbox is checked and then
> submit, all the selected rows will be deleted.
>
> <table>
> <?php
> //get results from db
> while($row = mysql_fetch_array ($result)) {
> ?>
> <tr>
> <td><input type="checkbox" name="delete" value="<?php
> print($row[id]);
> ?>"></td>
> </tr>
> <?php
> }
> ?>
> </table>
>
> what's the proper function i should write for this?
> also, can i put the function on the same page without useing SWITCH?
> i'm trying to minimize the number of files i have.
>
> thanks in advance for any help.
> wes
> www.devedeset.com
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>