RE: [phplib] OT: Deleting Queries from Checkbox From: Chester McLaughlin (chester <email protected>)
Date: 05/16/01

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>