Re: How to do this?

From: Date: Sat, 10 Apr 2004 21:53:58 +0000
Subject: Re: How to do this?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-183083@lists.php.net to get a copy of this message
Thanks a lot ----- Original Message ----- From: "John W. Holmes" <holmes072000@charter.net> To: "Mike Mapsnac" <mikerh9@hotmail.com> Cc: <php-general@lists.php.net> Sent: Saturday, April 10, 2004 10:34 AM Subject: Re: [PHP] How to do this? > Mike Mapsnac wrote: > > My php page takes data from the database such as ID, Date, Value and > > prints on the screen. About 20 entries are printed on the screen. The > > each entry has option 'yes' or 'no'. > > > > So I need to gather the information about each entry and update > > database. I cannot access the variable from $_POST because parameter is > > not static and $_POST is not working like this $_POST['$id']; > > Make a radio button such as: > > <input type="radio" name="option[<?=$id?>]" > value="Yes"> > <input type="radio" name="option[<?=$id?>]" > value="No"> > > Then, you'll have $_POST['option'][$id] that you can use. > > $yes_ids = array_keys($_POST['option'],'Yes'); > $yes_list = implode(',',$yes_ids); > > $no_ids = array_keys($_POST['option'],'No'); > $no_ids = implode(',',$no_ids); > > $entire_list = implode(',',array_keys($_POST['option'])); > > $query = "UPDATE table SET option = CASE WHEN id IN ($yes_list) THEN > 'Yes' WHEN id IN ($no_list) THEN 'No' END CASE WHERE id IN ($entire_list)"; > > Need to add in some validation, but that's the basic idea. Well, that's > not really "basic", but it gives you an idea of a very efficient way to > handle this. :) > > -- > ---John Holmes... > > Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ > > php|architect: The Magazine for PHP Professionals – www.phparch.com > > >

« previous php.general (#183083) next »