Log in

View Full Version : Add names from DB to a droplist



PatrikIden
02-12-2012, 12:33 AM
Hi i wonder how i can make this work:

I would like to have a dropdown list on my webpage containing names from DB
and when ever a new user registers on my site, and that info is added to DB the dropdown list should be updated whit this register users name.

Thank you.

fastsol1
02-12-2012, 03:43 PM
Fairly easy -
1. Echo a opening <select> with name attribute.
2. Run a query and select whatever info you want/need for the dropdown list.
3. Run a while loop form the db results and echo out a <option> foreach name for the list.
4. Echo a closing </select>.



echo '<select name="users">';
$get = mysql_query("SELECT `whatever` FROM `table_name`");
while($rows = mysql_fetch_assoc($get))
{echo '<option>', $rows['username'], '</option>';}
echo '</select>';

PatrikIden
02-13-2012, 08:39 PM
Hello, and thank you for your answer. This works, i get an dropdown list with all the names in DB. But i also use this: <?php echo mysql_result($result,$i,"Namn");?> in an text field to echo a name from DB but this will only show the firs name, So how can i get this to chang name when i pick another name from the dropdown list?
And of corse i have more textfileds with other values not just "Name", all of this fileds should shange when i pick another name from dropdown list?

Thank you.