Results 1 to 3 of 3

Thread: Add names from DB to a droplist

  1. #1
    Join Date
    Nov 2011
    Location
    Sweden
    Posts
    36
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Add names from DB to a droplist

    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.

  2. #2
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    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>.

    PHP Code:
    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>'

  3. The Following User Says Thank You to fastsol1 For This Useful Post:

    PatrikIden (02-12-2012)

  4. #3
    Join Date
    Nov 2011
    Location
    Sweden
    Posts
    36
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •