I have a multiple select box populated by an array at first.
I can enter into the db just fine and view the data fine.
However, when populating the box again with the VALUES that have already been selected is the problem. Any advice would help.
Thank you.
Here is my code.
This is the code for the multiple select:
<?php
function printHobbiesDrop($selectedValue, $dropName){
global $g_hobbies;
print "<select class=\"iform\" name=\"$dropName\" multiple=\"multiple\" >\n";
foreach( $g_hobbies as $key => $hobbiesName)
{
printf("<option value=\"%s\"%s>%s</option>\n", $key, (($key==$selectedValue)?" SELECTED":""), $hobbiesName);
}
echo "</select> Ctrl key and left click for multiple selections.";
}
?>
<?php
$g_hobbies = array(
'hobby1'=>'hobby1',
'hobby2'=>'hobby2',
'hobby3'=>'hobby3',
'hobby4'=>'hobby4',
'hobby5'=>'hobby5',
'hobby6'=>'hobby6',
'hobby7'=>'hobby7',
'hobby8'=>'hobby8',
'hobby9'=>'hobby9',
'hobby10'=>'hobby10',
'hobby11'=>'hobby11',
'hobby12'=>'hobby12',
'hobby13'=>'hobby13'
);
?>
This is the code used to display the choices to user for first time:
<?php printHobbiesDrop('', 'hobbies[]'); ?>
This is the code that allows the user to enter his/her choices into the db:
$all_hobby = implode(", ",$hobbies);
$result = mysql_query("insert into brothers values ('','$salutation','$firstname','$mi','$lastname','$address','$city','$state','$province','$zip','$country','$pledgeterm','$pledgeyr','$pledgeclass' ,'$pledgename' ,'$picture','$homephone','$workphone','$mobilephone','$industry','$title','$all_hobby','$bday','$profile','$username', password('$passwd'),'$email','$aolim', '$msnim', '$icq', '$privacy')");
And that works fine.
However,
once they are logged in the user may go and edit these choices. I wish to display what is already selected:
Here is the code I am using to display the choices on the edit profile page:
<?php printHobbiesDrop($row["hobbies"],'hobbies[]'); ?>
The choices selected though never render as selected.
What am I missing?[code=php]