在下拉列表中排除状态

时间:2018-07-29 02:09:33

标签: mysql select while-loop where

我试图在mobo表中排除status有缺陷的所有值,但是此代码不起作用。

它仍然显示我的下拉列表中的所有内容

<?php
$conn = new mysqli('localhost', 'root', 'admin2018', 'inventory') 
or die ('Cannot connect to db');
    $result = $conn->query("select mobo, status FROM mobo WHERE NOT 'status = Defective'");
    echo "<select name='mobo'>";

    while ($row = $result->fetch_assoc()) {

                  unset($id, $name);
                  $id = $row['mobo'];
                  $name = $row['mobo'];
                  echo '<option value="'.$id.'">'.$name.'</option>';

}
    echo "</select>";
?>

1 个答案:

答案 0 :(得分:0)

没关系,我已经使用它来解决

<?php
$conn = new mysqli('localhost', 'root', 'admin2018', 'inventory') 
or die ('Cannot connect to db');
    $result = $conn->query("select mobo, status FROM mobo WHERE status!='Defective'");
    echo "<select name='mobo'>";

    while ($row = $result->fetch_assoc()) {

                  unset($id, $name);
                  $id = $row['mobo'];
                  $name = $row['mobo'];
                  echo '<option value="'.$id.'">'.$name.'</option>';

}
    echo "</select>";
?>