Multi Select Form.

wxdqz

New Member
I am having a problem trying to return a select form with the options already selected.

Database of selected looks like this.

id_selected 1
data_selected 1,2,3,4,5,6

id_selected 2
data 5,8,9

Database for form is set like this

id 1
name Test

id 2
name Test2

id 3
name Test3

This is how I wrote the code but can not get it to work the way I need it to.
I am new to PHP so forgive the bad coding. I am just learning.

<SELECT MULTIPLE NAME="test[]">
<?
$stmt1 = "SELECT id, name FROM formdata ORDER BY name";
$sth1 = mysql_query($stmt1, $link);
while($row1 = mysql_fetch_array($sth1))
{
if(isset($update))for ($num = 0; $num < count($output); $num++):;
if (($row1[id]) == ($output[$num])){
printf("<option value='http://www.phpbuilder.com/board/archive/index.php/$row1[id]'selected>$row1[name]</option>\n");
}
endfor;
}
else{
printf("<option value='http://www.phpbuilder.com/board/archive/index.php/$row1[id]'>$row1[name]</option>\n");
}
}
}
?>
</SELECT>
 
Back
Top