4
Contributors
10
Replies
36
Views
2 Years
Discussion Span
Last Post by diafol
Featured Replies
  • 1
    diafol 3,669   2 Years Ago

    Please keep the discussion on site. State clearly what you want and we may be able to help. Asking contributors to search threads on other forums isn't really the way to go. Read More

  • 1
    diafol 3,669   2 Years Ago

    OK, well if you're happy with that, good luck. Many of us won't click links to external sites. Just a heads up. Read More

0

Assuming you use mysqli_ extension, here is a sample code that might help you.

<?php
    echo "<select>";
    $result = mysqli_query("SELECT * FROM table_name");
    while($row=mysqli_fetch_array($result)){
        echo "<option value='".$arr['option_number']."'>";
        echo  $row['option_name'];
        echo  "</option>";
     }
     echo "</select>";
?>
0
    <?php

        $link = mysqli_connect('localhost', 'root', 'admin','admin') or die("Could not connect database");
        $result=mysqli_query($link, "SELECT * FROM questions");
        $row = mysqli_fetch_assoc($result);
    ?>

        <label for="login-username">Secret Question:</label>
            <select name="sq" id="sq" style="width:250px; height:30px">

                <?php do { ?>
                        <option ><?php echo $row['question'];  ?></option>
                <?php } while ($row = mysqli_fetch_assoc($result)); ?>

            </select> 

Edited by abelingaw

0

that is good..
but i want chained dropdown list.

like the options shown in dropdownlist2 is dependable on options of dropdownlist1...

0

i have used this code but this is not working

<form name="f1" action="wel.php" method="post" target="_blank">
            <select id="dbase" name="dbase">
                <?php
                            $link = mysqli_connect('localhost', 'root', '','people') 
                                    or die("Could not connect database");
$result=mysqli_query($link, "show databases");
        while($row=mysqli_fetch_assoc($result))
                {
            echo "<option value='".$row['Database']."'>";
        }
            echo "</option>";

        ?>
        </select>

this is not showing options in dropdown list..

Edited by pritaeas: Removed password.

1

You forgot:
1)To use the </option> tag inside the while loop.
2) To give a name to the option.
Change the while part to the following one.

while($row=mysqli_fetch_assoc($result))
{
            echo "<option value='".$row['Database']."'>";
            echo $row['Database'];
            echo "</option>";
}
0

If you wanted a chained dropdown list, why didn't you state that in your original post? Have a look in the "code snippets" section of this forum. I provided 2 articles on linked dropdowns - you may find them useful.

1

Please keep the discussion on site. State clearly what you want and we may be able to help. Asking contributors to search threads on other forums isn't really the way to go.

1

OK, well if you're happy with that, good luck. Many of us won't click links to external sites. Just a heads up.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.