I've built a function which builds options for a SELECT FIELD. It draws options from a list table and then appends the SELECTED when the value that I am looping through in present in the $selected ARRAY.
In my $FieldValue, multiple values are delineated by a "\r". I use and Implode("/r", The Field) when saving it in to the DB. But when I EXPLODE() the value in this function, it does not create the ARRAY properly. With the debugging lines I've added, it looks like this:
Array
(
[0] => After Pastor
Appreciative Inquiry
Boundary Training
)
Here is the function:
function Get_Menu_Selected ($vType, $FieldValue) {
$options .= "<option value=\"\"></option>\n";
$qry = "select `vValue` FROM `vLists` where `vType`='$vType' ORDER BY `Sort` ASC";
$result=mysql_query($qry);
echo "fieldvalue ".nl2br($FieldValue);
$selected = explode('\r',$FieldValue);
echo "<pre>";
print_r ($selected);
echo "</pre>";
while($row=mysql_fetch_array($result)) {
$inst = $row['vValue'];
$sel = '';
if ( in_array($inst,$selected) ) {
$sel = 'selected="selected " ';
}
$options .= "<option {$sel}value=\"{$inst}\">{$inst}</option>\n";
} return $options;
}
Why is the the array not being built properly? I am hoping I am missing something simple.
Thanks ;-)