retrieve data from mysql database to display in a dropdown box with php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • viresh
    New Member
    • May 2007
    • 1

    retrieve data from mysql database to display in a dropdown box with php

    Hello everybody,
    I am quite beginner as a software professional in php & mysql. I want to know how I can fetch data from mysql database to show in a form's drop down box with php coding. I request all to help me in this regard.
    Sincerely,
    Vireshwar,
    Chennai,India
  • georgewashinton
    New Member
    • May 2007
    • 1

    #2
    [code=html]<html>
    <body>

    <?php

    $con=mysql_conn ect("localhost" ,"root","")
    or die('Could not connect: ' . mysql_error());


    mysql_select_db ("my_db", $con);

    $result = mysql_query("SE LECT username FROM users")
    or die("Invalid Query: " .mysql_query()) ;

    echo '<label>Select username:</label>';
    echo '<select id="username" name="username" >';
    echo '<option value="">Select </option>';

    while ($row = mysql_fetch_ass oc($result))
    {
    $va = $row['username'];
    echo "<option value='$va'>$va </option>";
    }
    echo '</select>';

    mysql_close($co n);
    ?>

    </body>
    </html>
    [/code]

    [Please use CODE tags when posting source code. Thanks! --pbmods]

    hope it would help you.
    Last edited by pbmods; May 23 '07, 03:27 AM. Reason: Added code tags.

    Comment

    Working...