Visitors Today: 7
Total Visits: 456994

XtremeXtension

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 7893 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

Fatal error: Uncaught Error: Call to undefined function mysql_escape_string() in /home/xtremgoo/laravel/public/comments/inc_rate.php:89 Stack trace: #0 /home/xtremgoo/laravel/public/pages/display.php(401): getComments('65', 'post') #1 /home/xtremgoo/laravel/public/body.php(18): include('/home/xtremgoo/...') #2 /home/xtremgoo/laravel/public/index.php(376): include('/home/xtremgoo/...') #3 {main} thrown in /home/xtremgoo/laravel/public/comments/inc_rate.php on line 89