On 18-May-2004 Miles Thompson wrote:
> 
> This is close to your situation, but I only needed a one dimensional
> array 
> for a bulk delete. So the form part has this line:
>          print( '<input type="checkbox" name=chkdelete[] value="' . 
> $myrow['sub_key'] . '">');
> There's no need for a subscript in the form - there are presently a 
> potential of 963 elements in this array. When we check for bulk
> delete it's 
> never contiguous, we skip down the list, so array is v. sparse.
> 
> And the processing part uses this loop:
> 
>          foreach ($chkdelete as $value){
>                  $sql = "delete from subscriber where sub_key =
> '$value'";
>                  $result = mysql_query($sql);
>          }
> 
> This way I'm in no danger of hitting a missing subscript as I might
> if I 
> used $chkdelete[ $i ], incrementing $i
> 

Since it's a checkbox and you'll only get "checked" values in the 
$_POST header; you just might as well use the subscript and skip the
loop entirely:
...

    if (count($_POST['chkdelete'])) {
        $lst = implode("','",array_keys($_POST['chkdelete']));
        $qry = "DELETE FROM subscriber WHERE sub_key IN ('$lst')";
        mysql_query($qry);
    }

...

Regards,

-- 
Don Read                                     [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to