Try some diagnostics to tell you what's going on

In the page you're submitting to try
Foreach($HTTP_POST_VARS as $key=>$value) echo("$key=>$value<br>");

Part of your problem may be that you're using the number of 
form elements returned to control the for loop. It doesn't
really have any significance in this context.

Is there any reason why you're not naming the checkboxes RG[1], RG[2], etc.?
This would make everything much easier - you can then do ...

Foreach ($HTTP_POST_VARS["RG"] as $value) $RGs[] = $value


Tim Ward
Internet Chess www.chessish.com <http://www.chessish.com> 

        ----------
        From:  Carlos Fernando Scheidecker Antunes
[SMTP:[EMAIL PROTECTED]]
        Sent:  30 April 2002 16:11
        To:  PHP-GENERAL
        Subject:  Problem with array

        Hello All,

        I've got a form that creates checkboxes based on the number of rows
on a table. The user has to check some of the boxes and then click submit.
The boxes are named RG1, RG2, RG3, ....

        If there are 4 checkboxes and the user selects them all or selects
the first, second and fourth, or the first third and fourth my code works.
But if the user selects the second, third and fourth (He does not checks the
first one) no information is recorded on my array.

        Here's the code that I have to search the $HTTP_POST_VARS and then
fill a array variable called $RG.


        function SearchRGs() {
            global $HTTP_POST_VARS;
            global $RGs;

            // fills the array variable RGs with the values of checked
checkboxes that start with the name RG# (where # goes from 1,2,3,....).
           // returns the qty of checked RGs and size of the $RGs array.

        $index = count($HTTP_POST_VARS);
        $count = 0;

        for ($i=1; $i < $index; $i++) {
            if (isset($HTTP_POST_VARS["RG$i"])) {
                $RGs[] = $HTTP_POST_VARS["RG$i"];
                $count++;
            }
        }

        return $count;

        }


        Can anyone help me with this?

        Why if I do not check the first checkbox on the form the array  is
not filled.

        Thank you,

        Carlos Fernando.

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

Reply via email to