Can't quite get the code in the right order

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simon_porter00
Forum Newbie
Posts: 13
Joined: Thu Feb 25, 2010 1:25 pm

Can't quite get the code in the right order

Post 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
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

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

Post 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.
simon_porter00
Forum Newbie
Posts: 13
Joined: Thu Feb 25, 2010 1:25 pm

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

Post 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
Post Reply