RE: [PHP] Help on dealing with arrays of HTTP_POST vars
| From: | Matt Schroebel | Date: | Mon, 15 Apr 2002 15:08:13 +0000 |
| Subject: | RE: [PHP] Help on dealing with arrays of HTTP_POST vars | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-93015@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Carlos Fernando Scheidecker Antunes
> [mailto:nando@antunes.eti.br]
>
> function SearchOrders() {
> global $Orders;
> global $HTTP_POST_VARS;
>
> $index = count($HTTP_POST_VARS);
>
> for($i=1; $i <= $index; $i++) {
The trouble is here ^^^^. You should be test for the max
Number of possible checkboxes, and not the number checked. If 3,4,5 are checked, then $index is 3,
bu thte varaiables will have names like
PED$3, PED$4, PEF$5 and your code will stop at 3.
> if (isset($HTTP_POST_VARS["PED$i"]))
> $Orders[] = $HTTP_POST_VARS["PED$i"];
> }
> $index = count($Orders);
> return $index;
Why not name the checkboxes as arrays like:
<input type="checkbox" name="PED[]" value="18191">
<input type="checkbox" name="PED[]" value="18192">
Then in php, PED[0] is the first *checked* value (so it could be the 5th checkbox). Test with
is_array to see if anything is check at all.