Hey so Im trying to display in an edit form what a user has previously selected when they first submitted this form. For a select menu I use this code which works flawlessly:
after connection to db and doing my query
<option name="name" <?php if ($loco_info[type] == "name") { echo " SELECTED"; } ?>>
now I don't know how to achieve the same thing using a MULTIPLE select menu. This information is stored in an array in the db so I was thinking I might have to use the in_array() function but i can't seem to get it to work. Here's what I currently have which doesn't work at all (although it does display the multiple select properly, it just doesn't show what has been selected according to the db):
ive got two queries one of which is not shown which is $user_profile[friends]. This is the array where what has been previously selected is stored in the db.
$query_n = "SELECT nickname, id from table ORDER BY nickname ASC";
$getnick = mysql_query($query_n);
while($nickname = mysql_fetch_assoc($getnick)) {
?>
<option value="<?php echo $nickname[id]; ?>"
<?php
$find = array($user_profile[friends]);
if (in_array($nickname[id], $find)) {
echo "SELECTED";
} ?>>
<?php } ?>
Here I'm trying to loop through the id's from the table and for each one I search within the friends array from a different table to see if there is a match and if so then echo SELECTED. any help please