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!'; }