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
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php