在WHERE中选择包含所有条件SQL

时间:2018-02-11 11:27:10

标签: mysql

我有多个下拉菜单,其中包含选项列表

    <select id="options">
    <option value="all" selected>All</option>
    <option value="1">Good</option>
    <option value="2">Bad</option>
    <option value="3">Okay</option>
    </select>
<select id="options1">
    <option value="all" selected>All</option>
    <option value="1">Good</option>
    <option value="2">Bad</option>
    <option value="3">Okay</option>
    </select>
<select id="options2">
    <option value="all" selected>All</option>
    <option value="1">Good</option>
    <option value="2">Bad</option>
    <option value="3">Okay</option>
    </select>

我使用此查询

        $result = mysqli_real_escape_string($connect, $_POST['options']);
        $result1 = mysqli_real_escape_string($connect, $_POST['options1']);
        $result2 = mysqli_real_escape_string($connect, $_POST['options2']);

$sql = mysqli_query($connect, "SELECT * FROM `table` WHERE `option` = '$result' AND `option1` = '$result1' AND `option2` = '$result2'");

如果选择了“all”选项,则SQL不返回任何内容,因为表中没有记录为“all”。如果选择“全部”,如何让它返回所有选项?考虑不同的下拉ID

1 个答案:

答案 0 :(得分:0)

像。

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="uniqueApp">
<div class="row" ng-controller="testController">
 <table>
  <tr ng-repeat="(key, value) in data.prize">
    <td> {{key}} </td> <td> {{ value }} </td>
  </tr>
</table>
</div>
</body>

这会对你有所帮助