Visitors Today: 152
Total Visits: 435091


Do you have source code, articles, and tutorials to share?
Visual Basic, VB.NET, C#, PHP/MySQL, C/C++, Java/JavaScript, ASP/ASP.NET, MS Access, FoxPro, SQL
You can write your own content here.


    If the information on this site helps you and you would like to make donation to please click the LINK below.

    If you want to support us, please make a contribution. Any amount is appreciated. To make a donation via PayPal, credit card, or e-check..

    Please click the DONATE link..

    Your contribution will make grow in the future.



Creating drop down lists from MySQL data

    Posted GraniteGear Posted On April 26, 2014

    PHP 0 Current Comments 6979 Views

    Like 8 people liked this.
     To create a drop down in a form in HTML you list the possible choices as OPTIONS in a SELECT element. PHP can create this list from MySQL data.

    The following code creates the form in HTML and starts PHP when it is needed:

       <form method="get" action="">

    # here database details      
    mysql_connect('hostname', 'username', 'password');

    $sql = "SELECT category FROM posts";
    $result = mysql_query($sql);

    echo "<select name='category'>";
    while ($row = mysql_fetch_array($result)) {
       echo "<option value='" . $row['category'] ."'>" . $row['category'] ."</option>";
    echo "</select>";

    # here category is the column of my table(posts)
    # it works perfectly


Share With Your Friends
Share Your Thoughts With Other Users

Be the first to comment.

Leave a Reply
This small test serves as access restriction against malicious bots.