RE: [PHP] [PHP4] Checkboxes and POST
| From: | Remco Chang | Date: | Wed, 09 Aug 2000 02:17:14 +0000 |
| Subject: | RE: [PHP] [PHP4] Checkboxes and POST | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-10825@lists.php.net to get a copy of this message | ||
that worked amazingly great. thank you very mcuh for the help! :)
----------------
remco chang
bountyquest.com
On Tue, 8 Aug 2000, Michael Richardson wrote:
> You can use the following:
>
> <?php
>
> print '<form method=post action=add.php>
> <input type=checkbox name="id[]" value="abc">ABC
> <input type=checkbox name="id[]" value="daf">DAF
> <input type=checkbox name="id[]" value="zwg">ZWG
> <input type=submit value=Submit>
> </form>';
> ?>
>
> This will place all of the values checked into elements of an array named
> id.
>
> You may name them using a method similar to what follows:
>
> while (odbc_fetch_into ($sql_result, &$array)) {
> $userid = $array[0] . '[]';
> $user_name = $array[1];
> echo "<input type=checkbox name=$userid value=1>$user_name";
> }
>
> To recall the values you can use:
>
> for ($i = 0; $i < count($id); $i++) {
> print $id[$i] . "<br>\n";
> }
>
> Hope this helps:
>
> RW
>
> -----Original Message-----
> From: Remco Chang [mailto:rkc@bountyquest.com]
> Sent: Tuesday, August 08, 2000 6:58 PM
> To: php-general@lists.php.net
> Subject: [PHP] [PHP4] Checkboxes and POST
>
>
> hi,
>
> i was wondering how PHP4 deals with the following:
>
> <?php
>
> echo"
> <form method=post action=add.php>
> <input type=checkbox name=id value="abc">ABC
> <input type=checkbox name=id value="daf">DAF
> <input type=checkbox name=id value="zwg">ZWG
> <input type=submit value=Submit>
> </form>";
> ?>
>
> if i check all three boxes, i end up getting only "ZWG" in add.php:
>
> <?php
> echo "id: $id";
> ?>
>
> i understand that the easiest way around it is to name each checkbox a
> different name. however, my problem is that i have a lot of checkboxes
> generated automatically based on the results of a database query:
>
> while (odbc_fetch_into ($sql_result, &$array)) {
> $userid = $array[0];
> $user_name = $array[1];
> echo "<input type=checkbox name=$userid value=1>$user_name";
> }
>
> the purpose of this is to let the current user add all the other users
> into his "group." but by doing the above, i have no effective way of
> finding out all the boxes/userid's that have been checked in the add.php
> file because i don't know the $userid's returned by the query...
>
> any suggestoins? comments? ideas?
>
> ----------------
> remco chang
> bountyquest.com
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>