来自mysql的多个下拉列表

I want to make multiple dropdowns from data out of my mysql database. I want 4 dropdowns to be exact. This is what I have at this moment:

<?php

mysql_connect('#', '#', '#');
mysql_select_db('test');

$sql = "SELECT wie, waar, metwie, voeruig FROM data";
$result = mysql_query($sql);

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

}
echo "</select>";
?>

For instance, this:

mysql_connect('#', '#', '#');
mysql_select_db('test');

$sql = "SELECT wie FROM data";
$result = mysql_query($sql);
echo "<select name='test1'>";
while ($row = mysql_fetch_array($result)){
    echo "<option value='" . $row['wie'] . "'>" . $row['wie'] . "</option>";
}
echo "</select>";

$sql = "SELECT waar FROM data";
$result = mysql_query($sql);
echo "<select name='test1'>";
while ($row = mysql_fetch_array($result)){
    echo "<option value='" . $row['waar'] . "'>" . $row['waar'] . "</option>";
 }
 echo "</select>";

$sql = "SELECT metwie FROM data";
$result = mysql_query($sql);
echo "<select name='test2'>";
while ($row = mysql_fetch_array($result)){
    echo "<option value='" . $row['metwie'] . "'>" . $row['metwie'] . "</option>";
 }
 echo "</select>";

$sql = "SELECT voeruig FROM data";
$result = mysql_query($sql);
echo "<select name='test3'>";
while ($row = mysql_fetch_array($result)){
    echo "<option value='" . $row['voeruig'] . "'>" . $row['voeruig'] . "</option>";
 }
 echo "</select>";
?>

As stated by HawasKaPujaari, avoid using mysql. Use mysqli. You could use a conditional switch statement like this:

        <?php
        $mysqli = new mysqli("localhost", "my_user", "my_password", "test");

        /* check connection */
        if ($mysqli->connect_errno) {
            printf("Connect failed: %s
", $mysqli->connect_error);
            exit();
        }


        /* Select queries return a resultset */
        if ($result = $mysqli->query("SELECT wie, waar, metwie, voeruig FROM data")) {

            printf("Select returned %d rows.
", $result->num_rows);

            while ($row = mysql_fetch_array($result)) {

            switch ($row) {
            case "wie":
                echo "<select name='wie'>";
                echo "<option value='" . $row['wie'] . "'>" . $row['wie'] . "</option>";
                echo "</select>";
                break;
            case "waar":
                echo "<select name='waar'>";
                echo "<option value='" . $row['waar'] . "'>" . $row['waar'] . "</option>";
                echo "</select>";
                break;
            case "metwie":
                echo "<select name='metwie'>";
                echo "<option value='" . $row['metwie'] . "'>" . $row['metwie'] . "</option>";
                echo "</select>";
                break;
            }
            case "voeruig":
                echo "<select name='voeruig'>";
                echo "<option value='" . $row['voeruig'] . "'>" . $row['voeruig'] . "</option>";
                echo "</select>";
                break;
            }

        /* free result set */
        $result->close();
        }
        ?>

php and mysql are different softwares. what you are doing here is connecting php with mysql using mysql_*() functions in your case what you get is an array in php. you can use this array for whatever you want. if you want to print array as is as for debugging use:

echo "<pre>";
print_r($row);
echo "</pre>";

From this you will get array structure then you ca use different dropdowns for array elements

Note: mysql_*() is not safe. Use mysqli_* or PDO.

Try code below. hope it help you

<?php
$wie=array();
$waar =array();
$metwie =array();
$voeruig =array();
while ($row = mysql_fetch_array($result)){
$wie[]=$row["wie"];
$waar[]=$row["waar"];
$metwie[]=$row["metwie"];
$voeruig[]=$row["voeruig"];

}
?> 
<select name="wie">
<?php
foreach($wie as $k=>$v)
{
?>
<option value="<?php echo $v?>"><?php echo $v;?>
<php 

}
?>
</option>
<select name="waar">
<?php
foreach($waar as $k=>$v)
{
?>
<option value="<?php echo $v?>"><?php echo $v;?> </option>
<php 

}
?>
</select>
<select name="metwie">
<?php
foreach($metwie as $k=>$v)
{
?>
<option value="<?php echo $v?>"><?php echo $v;?></option>
<php 

}
?>
</select>
<select name="voeruig">
<?php
foreach($voeruig as $k=>$v)
{
?>
<option value="<?php echo $v?>"><?php echo $v;?> </option>
<php 

}
?>
</select>

</div>