Hi everyone
I'll try to be as straightforward as possible. On my site is an address book that users can submit entries to. When you submit an entry there is a multiple select where u can choose friends of this entry from the database of previously submitted entries. This looks like this:
<SELECT NAME=friend_array[] size=5 multiple>
<?php
$sql_connection = mysql_connect("hostname","username","pass");
//mysql_select_db("table") or die("Cannot select database");
query_n = "SELECT nickname, id from addressbook ORDER BY nickname ASC";
$getnick = mysql_query($query_n);
$usernum = mysql_num_rows($getnick);
for ($count = 1; $count < $usernum + 1 ; $count++) {
$nickname = mysql_fetch_array($getnick);
?>
<option value="<?php echo $nickname[id]; ?>">
<?php echo $nickname[nickname]; ?>
<?php } ?>
So here im just looping through the database to get all the previously entered names and displaying the names with a value of their id. Everything works and I can display everything perfectly.
Now there is a feature where you can edit your previously entered address book people. It brings you to the form with all the values from the database entered in the form fields. My problem is how to show which of the options from above have been selected. Its easy with a single select or radio button but I can't figure out how to do it when its stored in an array. Since it is stored as an array (I unserialize to view) I thought I would have to use something like this:
$find = array($user_profile[friends]);
if (in_array($nickname[id], $find)) {
echo "SELECTED";
}
although this doesn't work since i guess friends (which is the var field in the db table where the multiple selects are stored) is an array. Any ideas?
Thanks