PDA

View Full Version : What's wrong with that loop?


Lionel
12-29-2005, 08:24 PM
Please someone help me. The below returns only one checkbox checked.
When I echo the two comparative values $player1[$p1] and $predplayer1 separately, the results are there. So if I have more than one result why is only one checkbox checked?


$predplayer1="$playerlname1 $playerfname1";
$player1=unserialize($getplayers1['players1']);
for ($p1 = 0; $p1 < count($player1);$p1++)
{
if ($player1[$p1]==$predplayer1){
$checkbox1 ="<input type=\"checkbox\" name=\"predplayer1[]\" value=\"$predplayer1\" checked>";
}
else {
$checkbox1="<input type=\"checkbox\" name=\"predplayer1[]\" value=\"$predplayer1\">";
}
}

filburt1
12-29-2005, 08:44 PM
Other than being really overcomplicated, what does it do?

If you're doing what I think you're doing (naming similar things with similar names, then ending with a number), then stop right now. It's a horrible practice that will bite you and anybody who tries to follow your code in the ass later.

Lionel
12-29-2005, 09:05 PM
What does it do? I am trying to populate checkboxes stored in database as serialized. I need to put a checkbox next to each player that is in the serializing.

People come and put their values. Later if they want to edit, the stored values should be at their places.
here (https://vborg.vbsupport.ru/attachment.php?attachmentid=40087)

Thanks God this is soccer so since I don't know how to extract that $i value from the array, I ended up doing the below 15 times, hoping that there won't be more than 15 goals in a game



if ($predplayer1==$player1[0] OR $predplayer1==$player1[1] OR $predplayer1==$player1[2] OR $predplayer1==$player1[3] OR $predplayer1==$player1[4] OR $predplayer1==$player1[5] OR $predplayer1==$player1[6])