Greetings,
I have the following problem:
In one form I create elements' names with the following code:
Code:
for ($i=1; $i<=$UserDefinedNumber; $i++)
{
echo ("<input type="checkbox" name=\"Married_$i\">");
}
Which means that If the user defined the $UserDefinedNumber = 3 it will create 3 checkboxes named:
Married_1,
Married_2 and
Married_3.
Now if we go to the next page and want to retrieve the values of them but we have no idea how many they are, we get a problem. How to "Assemble" the variables' names.
For example I tried the following code:
Code:
for ($i=1; $i<=$UserDefinedNumber; $i++)
{
if ("\$Married_" . $i == "on")
{
echo ("Yes");
} else {
echo ("No");
}
As most of you might have already assumed, I get an error. Iâve tried lots of variations in trying to "assemble" the variable's name but so far no success.
The point of doing this is not masochism but the fact that the loop might actually need to run lots of times (from 1 to 100 or even more) so I need to assemble the variable's name with a counter (
$i) exactly like I created them in the previous page.
Does anyone know how to do it? I'd really appreciate any help!
- Pericles
P.S.: Using an
array for this task [u]has failed</u>. Please check my previous post to see why:
http://p2p.wrox.com/topic.asp?TOPIC_ID=34923