selected option issue
Posted: Wed Jun 02, 2010 3:23 pm
Hi everyone,
I am using the below code in an edit page of movie information so in the genre field it displayed as selected the genres in the database.
My problem is that only one genre is showed as selected although the movie has more than 1 genre in the database.
Any idea why?
Thanks!!!
I am using the below code in an edit page of movie information so in the genre field it displayed as selected the genres in the database.
My problem is that only one genre is showed as selected although the movie has more than 1 genre in the database.
Any idea why?
Code: Select all
<?php
$select = "SELECT * FROM genres WHERE MovieID = '$id'";
$result = mysql_query($select);
$genreid = mysql_result($result, 0, 'GenreTypeID');
?>
<?php
$query = "SELECT * FROM genretypes ORDER BY Genre ASC";
$result2 = mysql_query($query);
while ($genre = mysql_fetch_array($result2)) {
$selected = "";
if ($genreid == $genre['GenreTypeID']) {
$selected = "selected=\"selected\"";
}
echo "<option $selected value=\"" . $genre['GenreTypeID'] . "\">" . $genre['Genre'] . "</option>";
}
?>