下面的代码显示表格中的数据,然后根据两个组合框的结果对其进行过滤。提交表单后,我可以按 ID 对结果进行排序,但不能在初始加载时(所有内容都列出)。我尝试过$sql = "SELECT * FROM Places ORDER BY ID";
在列表加载时哪个有效,但在提交表单时返回错误。希望这是有道理的。有任何想法吗?谢谢!
// Default query
$sql = "SELECT * FROM Places";
// check if form was submitted
if (isset($_POST['area'])) {
$connector = 'where';
if ($_POST['area'] != 'All') {
$sql .= " where Area = '".$_POST['area']."' ORDER BY ID";
$connector = 'and';
}
if ($_POST['theme'] != 'All') {
$sql .= " $connector Theme = '".$_POST['theme']."' OR Theme2 = '".$_POST['theme']."'
ORDER BY ID";
}
}