【发布时间】:2019-10-23 00:54:15
【问题描述】:
我正在尝试使用 MySQL 数据库和 PHP 为学校项目制作过滤器,但每当我按下过滤器按钮时,它都不会执行操作,因此查询字符串不会更新。
之所以引用我的主页是因为这个块代码:
if (empty($_GET['page'])) {
$_GET['page'] = 'home';
}
if (empty($routes[$_GET['page']])) {
header('Location: index.php');
exit();
}
这是没有$GET['page']传递的时候,它只会引用我的主页。
所以问题可能在于我的表单操作,这显然是正确的:action="index.php?page=agenda"
<form class="filter_form" method="get" action="index.php?page=agenda">
<div class="location">
<p class="filter_by">filter by:</p>
<label for="location">location</label>
<select name="location" id="location">
<option value="all">-- Locations --</option>
<?php foreach($locations as $location): ?>
<option value="<?php echo $location['location']; ?>"
<?php
if(!empty($_GET['location'])){
if($_GET['location'] == $location['location']){
echo ' selected';
}
}
?>
>
<?php echo $location['location']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="checker_wrapper">
<div>
<input type="checkbox" name="check1" id="check1">
<label for="check1">skills only</label>
</div>
<div class="bottom_row">
<input type="radio" name="group" id="radio1">
<label for="radio1">day</label>
</div>
</div>
<div class="radio_wrapper">
<div>
<input type="checkbox" name="check2" id="check2">
<label for="check1">in group</label>
</div>
<div class="bottom_row">
<input type="radio" name="group" id="radio2">
<label for="radio2">evening</label>
</div>
</div>
<input class="button filter_button" type="submit" value="filter" />
</form>
当我按下过滤器按钮时,我在主页中,查询字符串是这样的:index.php?location=all,所以我的项目的$_GET[location] 有效。只是没有在字符串中添加正确的页面。
【问题讨论】: