Visitors Today: 90
Total Visits: 400220

www.codester.info

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.

Donation


    If the information on this site helps you and you would like to make donation to XtremeXtension.com 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 XtremeXtension.com grow in the future.

Sponsor

Calendar

Creating drop down lists from MySQL data

    Posted GraniteGear Posted On April 26, 2014

    PHP 0 Current Comments 6781 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:
    SOURCE
    <body>

       <form method="get" action="http://www.XtremeXtension.com/process.php">

    <?php
    # here database details      
    mysql_connect('hostname', 'username', 'password');
    mysql_select_db('database-name');

    $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
    ?>

      </form>
       
    </body>  





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.