Re: Multiple Update from one form

From: Date: Thu, 20 May 2004 05:52:59 +0000
Subject: Re: Multiple Update from one form
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-186569@lists.php.net to get a copy of this message
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 dread@ispwest.net -- 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.

« previous php.general (#186569) next »