|
Posted by Tyno Gendo on 04/04/07 12:47
Jerim79 wrote:
> and passing it along as hidden button on the form. $Age'$Number'
> seemed to work for creating the variable, but $_post["Age'$Number'"]
> doesn't work for referencing the global variable. I would need some
> way of looping through and dynamically creating the variables.
>
> I am willing to rethink my approach to the whole problem, so the door
> is wide open to suggestions.
Firstly, I'd get rid of the single quotes at they come out as
Age'1', but you probably want Age1
For an unknown number of ages you could do:
$ages=array();
foreach( $POST as $key=>$value ) {
if (substr($key,0,3)=="Age") {
$ages[$key]=$_POST[$key];
}
}
If there were 5 ages you would end up with
$ages["Age1"] = <age_entered1>;
$ages["Age2"] = <age_entered2>;
$ages["Age3"] = <age_entered3>;
$ages["Age4"] = <age_entered4>;
$ages["Age5"] = <age_entered4>;
If you don't want an array, you can do:
foreach( $POST as $key=>$value ) {
if (substr($key,0,3)=="Age") {
${$key}=$_POST[$key];
}
}
The ${$key} would make your variables $Age1, $Age2 etc.
Hope that helps, untested, let me know.
Navigation:
[Reply to this message]
|