Date: 05/16/01
- Next message: Ben Curtis: "Re: [phplib] OT: Deleting Queries from Checkbox"
- Previous message: Layne Weathers: "RE: [phplib] OT: Deleting Queries from Checkbox"
- Maybe in reply to: HurricaneIndy <email protected>: "[phplib] OT: Deleting Queries from Checkbox"
- Next in thread: Arno A. Karner: "Re: [phplib] OT: Deleting Queries from Checkbox"
- Reply: Arno A. Karner: "Re: [phplib] OT: Deleting Queries from Checkbox"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
When you're looping through the returned records from the database
and creating you're form, add a "[]" to the end of the check box
element name... ex:
$db->query("SELECT row_id FROM some_table WHERE something=something_else");
while ($db->next_record()){
$row_id = $db->f("row_id");
echo "<input type='checkbox' name='del[]' value='$row_id'>\n"
}//end while
Then when the form is submitted, you'll have an array named $del that
contains all the row_id's that need to be deleted. You can then
either delete them one by one, or concatenate them all together for a
nice monster query. ex:
while (is_array($del) && list($key,$row_id) = each($del)){
if ($query_string == ""){
$query_string = "row_id='$row_id'"
} else {
$query_string .= " OR row_id='$row_id'";
}//end if
}//end while
You'll then have a string you can use like this:
$query = sprintf("DELETE FROM some_table WHERE %s",$query_string);
$db->query($query);
Viola!
>Hey all,
>I have query that lists all the rows in a table. I would like to be
>able to delete any of them using a checkbox. I added the checkbox
>tags in a while loop along with the rest of the queries so it prints
>out nicely. Of course I have a statement like:
>
>mysql_query("DELETE FROM test_table WHERE ????")
>
>This is the part I am stuck at...How exactly do I write this part of
>the code not knowing how many checkboxes will be selected to delete?
>
>Thanks in advance guys..
>
Indy
---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-unsubscribe <email protected>
For additional commands, e-mail: phplib-help <email protected>
- Next message: Ben Curtis: "Re: [phplib] OT: Deleting Queries from Checkbox"
- Previous message: Layne Weathers: "RE: [phplib] OT: Deleting Queries from Checkbox"
- Maybe in reply to: HurricaneIndy <email protected>: "[phplib] OT: Deleting Queries from Checkbox"
- Next in thread: Arno A. Karner: "Re: [phplib] OT: Deleting Queries from Checkbox"
- Reply: Arno A. Karner: "Re: [phplib] OT: Deleting Queries from Checkbox"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

