作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用单选按钮创建了一个过滤器选项。单选按钮值存储在 PHP session 中。对于“state”单选按钮,其值存储在 $state=$_SESSION["state"];而“条件单选按钮存储在 $condition=$_SESSION["condition"]; 中。以下是按钮值的列表:
状态:
-全州
-新的-老的-未知状态
条件:-所有条件- 可用/未分配-指定的-维修-遗失的部分-missingeq- 翻新-未知情况
<?php
if($state=='allstate' AND ($condition=='Available/Unassigned' OR $condition=='assigned' OR
$condition=='repair' OR $condition=='missingpart' OR $condition=='mmissingeq' OR
$condition=='defective' OR $condition=='refurbished' OR $condition=='Unknown condition')){
$sql = ("SELECT * from eq_inv left JOIN empl_tbl on eq_inv.empl_no=empl_tbl.empl_no WHERE
eq_condition='$condition' AND (eq_state='new' OR eq_state='old' OR eq_state='Unknown state') ORDER
BY empl_firstname, empl_lastname, middlename ASC");
}
if($state=='allstate' AND $condition=='allcondition'){
$sql = ("SELECT * from eq_inv left JOIN empl_tbl on eq_inv.empl_no=empl_tbl.empl_no WHERE
eq_condition='Available/Unassigned' OR eq_condition='assigned' OR eq_condition='repair' OR
eq_condition='missingpart' OR eq_condition='missingeq' OR eq_condition='refurbished' OR
eq_condition='Unknown condition') AND (eq_state='new' OR eq_state='old' OR eq_state='Unknown State')
ORDER BY empl_firstname, empl_lastname, middlename ASC");
}
if($condition=='allcondition' AND ($state=='new' OR $state=='old' OR $state=='Unknown state')){
$sql = ("SELECT * from eq_inv left JOIN empl_tbl on eq_inv.empl_no=empl_tbl.empl_no WHERE
eq_state='$state' AND (eq_condition='Available/Unassigned' OR eq_condition='assigned' OR
eq_condition='repair' OR eq_condition='missingpart' OR eq_condition='missingeq' OR
eq_condition='refurbished' OR eq_condition='Unknown condition') ORDER BY empl_firstname,
empl_lastname, middlename ASC");
}
else{
$sql = ("SELECT * from eq_inv left JOIN empl_tbl on eq_inv.empl_no=empl_tbl.empl_no WHERE
eq_state='$state' AND eq_condition='$condition' ORDER BY empl_firstname, empl_lastname, middlename
ASC");
}
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($result)) {
?>
<td>-td content-</td>
</tbody>
<?php
}
?>
我做了四个场景,但只有if($condition=='allcondition' AND ($state=='new' OR $state=='old' OR $state=='未知状态'))
和
else{ $sql = ("SELECT * from eq_inv left JOIN empl_tbl on eq_inv.empl_no=empl_tbl.empl_no WHERE eq_state='$state' AND eq_condition='$condition' ORDER BY empl_firstname, empl_lastname, middlename ASC"); }
正在工作。
最佳答案
我意识到解决方案是如此简单。我只是将一些 if() 语句更改为 elseif() 语句。它应该遵循创建 if()、elseif() 和 else{} 语句的格式。
<?php
if($state=='allstate' && $condition=='allcondition'){
$sql = ("SELECT * from eq_inv left JOIN empl_tbl on eq_inv.empl_no=empl_tbl.empl_no
WHERE eq_state='new' OR eq_state='old' OR eq_state='Unknown state'
AND(eq_condition='Available/Unassigned' OR eq_condition='assigned' OR
eq_condition='repair' OR eq_condition='missingpart' OR eq_condition='missingeq' OR
eq_condition='refurbished' OR eq_condition='Unknown condition')
ORDER BY empl_firstname, empl_lastname, middlename ASC");
}
elseif($state=='allstate' AND ($condition=='Available/Unassigned' OR
$condition=='assigned' OR $condition=='repair' OR $condition=='missingpart' OR
$condition=='mmissingeq' OR $condition=='defective' OR $condition=='refurbished' OR
$condition=='Unknown condition')){
$sql = ("SELECT * from eq_inv left JOIN empl_tbl on eq_inv.empl_no=empl_tbl.empl_no
WHERE eq_condition='$condition' AND (eq_state='new' OR eq_state='old' OR
eq_state='Unknown state') ORDER BY empl_firstname, empl_lastname, middlename ASC");
}
elseif($condition=='allcondition' AND ($state=='new' OR $state=='old' OR
$state=='Unknown state')){
$sql = ("SELECT * from eq_inv left JOIN empl_tbl on eq_inv.empl_no=empl_tbl.empl_no
WHERE eq_state='$state' AND (eq_condition='Available/Unassigned' OR
eq_condition='assigned' OR eq_condition='repair' OR eq_condition='missingpart' OR
eq_condition='missingeq' OR eq_condition='refurbished' OR eq_condition='Unknown
condition') ORDER BY empl_firstname, empl_lastname, middlename ASC");
}
else{
$sql = ("SELECT * from eq_inv left JOIN empl_tbl on
eq_inv.empl_no=empl_tbl.empl_no WHERE eq_state='$state' AND eq_condition='$condition'
ORDER BY empl_firstname, empl_lastname, middlename ASC");
}
关于php - 使用单选按钮的过滤器选项的嵌套 AND 和 OR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59532010/
我是一名优秀的程序员,十分优秀!