P粉9305342802023-07-26 09:07:18
首先,我不明白如何同时选择两个单选按钮,你是指复选框吗?关于你的问题 - 无论如何,你应该执行一个查询,但根据你的$_POST值构建它
可能是这样的:
// make an empty array to hold all the conditions $whereValues = []; // populate the array with conditions if (in_array($_POST['searcha'], $search_a_option_list)) { $whereValues[] = "inth = '$_POST[searcha]'"; } else if ($_POST['searchb']) { $whereValues[] = "bunty LIKE '%$_POST[searchb]%'" } else if (isset($_POST['radio1'], $_POST['radio2'])) { $whereValues[] = "ref = 'In' OR ref1 = 'On'" } else if (isset($_POST['radio1'])) { $whereValues[] = "ref = 'In'" } else if (isset($_POST['radio2'])) { $whereValues[] = "ref1 = 'On'" } // if we have something then build the result string of `WHERE` conditions if ($whereValues) { $where = implode(' AND ', $whereValues); $stmt = $pdo->prepare("SELECT * FROM coun WHERE $where"); $stmt->execute(); $search_results = $stmt->fetchAll(PDO::FETCH_ASSOC); } else { $error = 'No options selected!'; }