Re: How to emulate phpMyadmin for editing with checkboxes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank you for your generous response.
I am almost there, but not quite.

I changed my checkbox statement to looke like the following:

<INPUT type="checkbox" name="isSelected[]" value="<?php $row['ID'] ?>" >

where "ID" is the name of the auto-incremental id of my table.

This is the output I get from my post_r debug statement:


Array ( [isSelected] => Array ( [0] => [1] => [2] => )

   [SUBMIT] => Edit
)

As I was debugging I tried the checkbox statement without the value attribute or parameter, so it looked like the following:

<INPUT type="checkbox" name="isSelected[]" >

and the debug info from post_r is the following

Array
(
   [isSelected] => Array
       (
           [0] => on
           [1] => on
           [2] => on
       )

   [SUBMIT] => Edit
)

which makes me wonder whether or not an 'int' value can be input for the value of a checkbox array.




From: John Holmes <holmes072000@xxxxxxxxxxx>
To: Mahmoud Badreddine <runnerbrain@xxxxxxxxxxx>
CC: php-db@xxxxxxxxxxxxx
Subject: Re:  How to emulate phpMyadmin for editing with checkboxes
Date: Wed, 23 Feb 2005 22:11:18 -0500

Mahmoud Badreddine wrote:
Problem statement:
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.

Details:
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... :)

--

---John Holmes...

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



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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux