OK, I have searched and searched and can't seem to figure out exactly how to do this -- I think my syntax on some solutions may have been off, but I am not sure.
I want to take a pipe-delimited string and cycle through the contents so I can mark associated check boxes as checked or not.
Right now I have taken a short-cut/cheat:
Let's say I have a group of check boxes for a form. These check boxes are multiple selection named: performed[].
Upon processing I have the chosen boxes (each numbered sequentially) placed into a pipe delimited string and stored in my database. So if buttons 1 and 5 were checked I would have the following data: 1|5
Late when I need to be able to list or change the selected check boxes I want to be able to simply cycle through the pipe delimited list and set a variable related to each checkbox. ie: $selected1 = "checked"
Then I can simply set the appropriate echo in each checkbox tag.
<input name="performed[]" type="checkbox" <?=$selected1?> value="1">
Right now I have to cycle through the array and find my matches and then manually forcecheck each possible increment to set the variable to "CHECKED."
There has to be a way to do this more elegantly than entering a separate line of code for each incremented option. Right now I am using:
if ($array_str[$i] == "1") { $selected1 = "checked"; }
if ($array_str[$i] == "2") { $selected2 = "checked"; }
etc
etc
Thats fine for now, but is there something possible like:
$selected{$i} = "checked";
<?
$array_str = explode("|", "$performed");
for($i=0; $i<count($array_str); $i++) {
[INDENT]if ($array_str[$i] != '') {
if ($array_str[$i] == "1") { $selected1 = "checked"; }
if ($array_str[$i] == "2") { $selected2 = "checked"; }
if ($array_str[$i] == "3") { $selected3 = "checked"; }
if ($array_str[$i] == "4") { $selected4 = "checked"; }
if ($array_str[$i] == "5") { $selected5 = "checked"; }
if ($array_str[$i] == "6") { $selected6 = "checked"; }
}[/INDENT]
}
?>
Thanks!