I would like to give my users the option of clicking on a checkbox which I have provided as a field in a table and then clicking on the edit (or delete ) button to edit the info pertaining to the checked record.
In other words , in case my statement of the problem isn't clear, I would like to do the editing or deletion the same way it's done in phpMyadmin. Click on the checkbox followed by the desired action.
I have included in my table a field which I have called "chosen" which is of type enum('1','0')
As soon as I hit the "edit" button , I am redirected to a php script. In that scritp the first action I would like to make is to update the field chosen from the value '0' to the value '1'.
This way I will be able to update based on the value of that field. But my problem is how to link the checkbox input to this field. The checkbox input is blind to which record it is acting upon. But there must be a way.
Each record has an ID, right? So set the value of the checkbox to the ID of the record. Make the checkboxes an array, also.
<input type="checkbox" name="choices" value="<?=$record['id']?>">
Do that for each checkbox. When the form is submitted, you'll have $_POST['choices'] that contain the IDs of all the records selected. array_values($_POST['choices']) will give you the values or you can loop through the array yourself.
Now perform whatever "action" was selected. The action can be a value passed from a drop down select box. No need for a "chosen" column in the database. You'll just run into trouble with that anyhow, because how do you get the records back to "unchosen"? How do you determin who "chose" a record? What happens if they choose records, but don't perform an action? If their browser or computer crashes? etc... :)
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals – www.phparch.com
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php