Welcome to Welcome to DNF.com™ - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars

If you are new to domains and looking to buy, sell and learn about domains then you have come to the right place. DNForum is the largest domain name community on the internet and continues to grow every day. There are over 105,000 domainers on DNForum doing everything from buying domains, selling domains, learning about domains and discussing domains. Take a minute and Register.

Register Today on DNForum IT'S FREE!

Results 1 to 4 of 4
  1. #1
    Platinum Lifetime Member
    MrDude's Avatar
    Join Date
    Jun 2005
    Location
    UK
    Posts
    1,249
    DNF$
    90
    Bank
    0
    Total DNF$
    90
    Donate  

    PHP/MySQL setting selected option for Dropdown Menu

    I always see it on forums and stuff, when you go to edit your profile, your date of birth or whatever you put in a dropdown menu is shown to you, exactly how you selected it.

    I have a form where people enter their date of birth, location etc, and I want it so when they go to edit, they see their selections already selected in the dropdown list by adding selected='selected' to it, I really cant figure out how to do it, and my only workaround right now is to add a duplicate at the top of the dropdown list.

  2. #2
    DNF Addict
    south's Avatar
    Join Date
    Dec 2006
    Location
    33143/04930
    Posts
    4,905
    DNF$
    6,764
    Bank
    0
    Total DNF$
    6,764
    Donate  
    I don't fully understand the question, but I'm guessing you are looking for a script that will populate a form based on the drop down menu?

    Try this to get some ideas: http://www.codingforums.com/showthread.php?t=80345
    Last edited by south; 03-20-2009 at 08:03 AM.
    All offers good for 72 hours except running auctions

    Progeria Research | Pulmonary Fibrosis | Dammit!

  3. #3
    Country hopper
    katherine's Avatar
    Join Date
    Jul 2005
    Location
    Up north
    Posts
    7,171
    Country

    Iceland
    DNF$
    31,103
    Bank
    0
    Total DNF$
    31,103
    Donate  
    Here is one example.

    The idea is that when the form loads, you retrieve their saved data from the DB. Let's just fetch their year of birth as an example.
    Then you build your combo using a loop (here current year = 2009 through 1909). The year that matches your variable gets the selected attribute.

    PHP Code:
    <?php
    $link
    =mysql_pconnect("localhost","user","password");
    mysql_select_db("db",$link);
    $result mysql_query("select date_format(birth_date,'%Y') as birth_year from members where member_id=1");

    $row=mysql_fetch_array($result); // fetch first row
    $year=$row["birth_year"]; // retrieve 4-digit year of birth

    // display combo: current year -> -100
    $current_year=date("Y");
    echo 
    '<select name="cbo_year">';
    for (
    $i $current_year$i >= ($current_year-100); $i--) {
    echo 
    '<option '.($year == $i ' selected ' '').' value="'.$i.'" >'.$i.'</option>';
    }
    echo 
    '</select>';
    ?>
    For XHTML compliant code use this instead
    PHP Code:
    echo '<option '.($year == $i ' selected="selected " ' '').' value="'.$i.'" >'.$i.'</option>'
    NameNewsletter.com - free lists of available domain names
    ZoneFiles.net (beta) - ccTLD and gTLD droplists

  4. #4
    Platinum Lifetime Member
    MrDude's Avatar
    Join Date
    Jun 2005
    Location
    UK
    Posts
    1,249
    DNF$
    90
    Bank
    0
    Total DNF$
    90
    Donate  
    Thankyou!

    That was exactly what I was looking for with regards to their date of birth, but my biggest pain is Location of the users, with a long dropdown list is there an easy way about it? Its not really important, im just looking to have things working properly, if its too much hassle for me I may just duplicate their location such as "United States" at the top of the list.

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
  •  

Domain name forum recommended by Domaining.com