eMonk Posted April 25, 2011 Share Posted April 25, 2011 I'm not sure what to search for or if this can be done... Let's say I have a mysql table named "genre". Now I have "Male" and "Female" in a dropdown menu like this in a form: <select name="genre"> <option>Male</option> <option>Female</option> </select> How would you display, for example, the option Female in a update.php file if that's the genre stored in the mysql database when you fetch the results? Quote Link to comment Share on other sites More sharing options...
Zane Posted April 25, 2011 Share Posted April 25, 2011 You simply add selected to the option tag Female If there's any HTML validity problems then you'll have to give selected a value of selected. Female Quote Link to comment Share on other sites More sharing options...
eMonk Posted April 25, 2011 Author Share Posted April 25, 2011 I'm trying to update the genre in a php/mysql form though. Is it possible to select the genre stored in the database, for example, Female and then have the other option under it (Male) so I can update it to Male if needed and vice versa? I was thinking along the lines of: <option><? echo($genre); ?></option> But not sure how you would include the other options or if this can even be done. Quote Link to comment Share on other sites More sharing options...
Zane Posted April 25, 2011 Share Posted April 25, 2011 In order to include dynamic options, the options MUST be in a database. Quote Link to comment Share on other sites More sharing options...
floorfiller Posted April 25, 2011 Share Posted April 25, 2011 give me just a moment i think i have some code written up for this... here is the PHP portion... <?php $connect = mysql_connect('localhost' , 'root' , '') or die(); $db = mysql_select_db('database') or die(); $select = "SELECT genreID , genre_type FROM genre"; $result = mysql_query($select); $options = ""; While ($row = mysql_fetch_array($result)) { $genreID = $row["genreID"]; $genre = $row["genre_type"]; $options .= "<option=\"$genreID\">".$genre; } ?> Here is the HTML portion... <html> <table> <th>Genre</th> <tr> <td><select name="genres"><?php echo $options; ?></td> </tr> </table> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.