gpt4 book ai didi

php - 使用单选按钮的过滤器选项的嵌套 AND 和 OR

转载 作者:行者123 更新时间:2023-11-29 09:26:29 25 4
gpt4 key购买 nike

我使用单选按钮创建了一个过滤器选项。单选按钮值存储在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com