Re: [phplib] OT: Deleting Queries from Checkbox From: Arno A. Karner (karner <email protected>)
Date: 05/16/01

using a row id will not work if the data base changes in between the
displayed form and the submit of the form. if there is a unique id field
use it instead of row number, or make the value from concatated fields
that will give you a unique key.

just my 2 cents.

Chester McLaughlin wrote:
>
> 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>

-- 
My opinions are my own and not that of my employer even if I am self
employed
Tech Net, Inc.            --FREE THE MACHINES--                 
651.224.2223
627 Palace Ave. #2           karner <email protected>              
karner <email protected>
St. Paul, MN 55102-3517        www.tnss.com         
wanted    : adsl/cable modem with static ip at reasonable price
accept-txt: us-ascii,html,pdf
accept-dat: ascii-delimited,sql insert statments

--------------------------------------------------------------------- To unsubscribe, e-mail: phplib-unsubscribe <email protected> For additional commands, e-mail: phplib-help <email protected>