Get Data in dropdown list from database

Discussion in 'PHP' started by minhazikram, Dec 1, 2011.

  1. #1
    <html>
    <head>
    <script type="text/javascript" src="select.js">
    </script>
    </head>
    <body>

    <select id="secelctThis">
    <option selected ="selected">Select a Destination</option>
    <option value="http://www.google.com">Google</option>
    <option value="http://www.facebook.com">Facebook</option>
    <option value="http://www.gmail.com">Gmail</option>
    </select>

    </body>
    </html>

    this is my code. I need to retrieve value field from the database. Can anyone tell me how to get data from Data Base in the drop down list.
     
    minhazikram, Dec 1, 2011 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    In your PHP file (this is pseudocode - the exact code depends on your database and how you prefer getting data from it):
    
    <html>
    <head>
    <script type="text/javascript" src="select.js">
    </script>
    </head>
    <body>
    
    <?php
    //code to get your data into a recordset
    ?>
    <select id="seelctThis">
    <option selected ="selected">Select a Destination</option>
    <?php
    //while not end of the recordset
    echo '<option value='.recordset field 1.'>'.recordset field 2.'</option>';
    ?>
    </select>
    
    </body>
    </html>
    
    PHP:
     
    Rukbat, Dec 1, 2011 IP