Page 1 of 1

Can't quite get the code in the right order

Posted: Tue Sep 14, 2010 2:14 pm
by simon_porter00
Hello All,
Usual scenario - php noob trying to get something simple right without actually managing it
I've got the following code:

Code: Select all

$string9 = ($_POST['level']);


$alevel = $string9;


$N=count($alevel);

for($i = 0; $i < $N; $i++) 

if ($level == "AAA"){
print ("111");
} elseif ($level == "BBB"){
print ("222");
}
else {
print ("333");
}

{

echo("<h2>You chose: <font color=#04B404>" .$alevel[$i] . "</font> <input type=checkbox name=level[] checked=yes value=" .$alevel[$i] . "></h2>\n");

}

}
And it's giving me the result:

111
You chose: (here's the tick box)

The text should look like: You chose: 111 (here's the tick box)

Any idea what I'm getting wrong? Many thanks in advance

Re: Can't quite get the code in the right order

Posted: Tue Sep 14, 2010 3:39 pm
by cpetercarter
I am not certain that I understand what you want to achieve. However, if your code is:

Code: Select all

echo("<h2>You chose: <font color=#04B404>" .$alevel[$i] . "</font> <input type=checkbox name=level[] checked=yes value=" .$alevel[$i] . "></h2>\n");
and you want the output to be
You chose: 111 (here's the tick box)
then you have to assign the value '111' to $alevel[$i]. At the moment you are printing the value '111' to the screen and not assigning it to anything.

Re: Can't quite get the code in the right order

Posted: Tue Sep 14, 2010 5:01 pm
by simon_porter00
Thanks for your reply - you pushed me in the right direction and with a bit of tinkering I got it doing what I wanted - many thanks