RE: [PHP] Re: Dynamically check radio buttons
| From: | Mark Middleton | Date: | Thu, 01 Aug 2002 15:47:45 +0000 |
| Subject: | RE: [PHP] Re: Dynamically check radio buttons | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-110688@lists.php.net to get a copy of this message | ||
It looks like your code could use "variable variables" to help you out.
::::::::::: OLD CODE ::::::::::::::::
> > for ($GameIdx = 1; $GameIdx <= 17; $GameIdx++) {
> > /* instead "hardcoding each radio button name - just do it
> programmatically
> > by concatenating / creating the name */
> > $frmGame = "Game" + $GameIdx;
> > if ($frmGame) {
::::::: END OF OLD CODE :::::::::::::
** this check will always be true - because you just set $frmGame equal to a
value... ***
What you want to do at this point is use variable variables (where the
variable name is actually
a variable itself.
::::::::: NEW CODE :::::::::::
> > $var_frmGame = "Game" + $GameIdx;
> > $frmGame = $$var_frmGame; // The "$$" is used for variable variables
> > if ($frmGame) {
:::::: END OF NEW CODE :::::::
** the above snippett is was I wrote to show the results of the dynamic
(looped-through) variable $Game1, $Game2, ...
I use this method when the number of form elements is variable. Instead of
hardcoding the number "17" you might make a variable in the incoming form
with the count of form elements (simply increment a variable with each
printing of the form variable... then at the end of the form make <input
type="hidden" name="elementcount" value="$count">)
Then you can make the above for-statement look like this:
> > for ($GameIdx = 1; $GameIdx <= $elementcount; $GameIdx++) {
Does any of this make sense or help in any way?
-Mark