选定的下拉框显示来自mysql数据库的2个值

时间:2017-01-02 02:42:10

标签: php mysql database phpmyadmin implode

嘿,我从我的数据库中检索的下拉菜单值有问题。我看到两个值而不是一个。

$con = mysqli_connect("localhost","root","") ;
$myDB = mysqli_select_db($con, "test");
$dbEnc = mysqli_set_charset($con, 'utf8');

$sqlSELECT = mysqli_query($con, 'SELECT class FROM disastergroups'); 

<!DOCTYPE html>
<html>
    <head>
        <title>test</title>
        <meta http-equiv="content-type" content = "text/html; charset=utf-8"/>
    </head>
    <body>
        <select name="test">
            <option value="">Select...</option>
            <?php while ($row1 = mysqli_fetch_array($sqlSELECT)): ;?>
            <option><?php echo implode("\t", $row1); ?></option>
            <?php endwhile;?>
        </select>
        <input type="submit" value="Submit Data">
    </body>
</html>

下图显示了下拉菜单中的重复项...如何解决此问题?

CLICK HERE FOR IMAGE

1 个答案:

答案 0 :(得分:2)

这是因为mysqli_fetch_array()for intf in get_interfaces_with_mac_addresses('Realtek'): print intf['Name'], intf['MACAddress'] 默认值为resulttype - &gt; int $resulttype = MYSQLI_BOTH。改变 -

mixed mysqli_fetch_array ( mysqli_result $result [, int $resulttype = MYSQLI_BOTH ] )

while ($row1 = mysqli_fetch_array($sqlSELECT)):

或者,只需使用mysqli_fetch_assoc()

while ($row1 = mysqli_fetch_array($sqlSELECT, MYSQLI_ASSOC)):

这样您只能获得1值,并且可以移除while ($row1 = mysqli_fetch_assoc($sqlSELECT)): - &gt;

implode()