whelpton Posted March 14, 2009 Share Posted March 14, 2009 Hi guys, I was wondering weather it would be possible to take the contents of a mysql table and insert it into a drop down form. My mysql table is called "Users" and I want to take the row "Username" and output it so that it displays all the current usernames in a form field such as: <select name="select" id="select"> <option>USERNAME1</option> <option>USERNAME2</option> </select> Obviously replacing the static username 1 and username 2 with the content from the mysql table Quote Link to comment Share on other sites More sharing options...
ccchan Posted March 14, 2009 Share Posted March 14, 2009 Would it look something like this: <select class="input2" name="username"> </option><? $query = "SELECT * FROM user ORDER BY username ASC"; $result = @mysql_query($query); if ($result){ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo '<option value="'.$row['username'].'"'; if ($_POST['username'] = $row['username']){echo 'selected="selected"';} echo '>'.$row['username'].'</option>';}} ?></select> I actually totally made this for something that I made a while back. Adjust it accordingly... If it works for you at all... I'm kind of a noob. Quote Link to comment Share on other sites More sharing options...
Festy Posted March 14, 2009 Share Posted March 14, 2009 Would it look something like this: <select class="input2" name="username"> </option><? $query = "SELECT * FROM user ORDER BY username ASC"; $result = @mysql_query($query); if ($result){ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo '<option value="'.$row['username'].'"'; if ($_POST['username'] = $row['username']){echo 'selected="selected"';} echo '>'.$row['username'].'</option>';}} ?></select> I actually totally made this for something that I made a while back. Adjust it accordingly... If it works for you at all... I'm kind of a noob. That should work ok. Just use '<?php' instead of '<?'. Because you could get errors if short tags are not on in php.ini Quote Link to comment Share on other sites More sharing options...
whelpton Posted March 14, 2009 Author Share Posted March 14, 2009 That worked perfectly, thank you so much 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.