我正在尝试使用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]
可以正常工作。只是没有在字符串中添加正确的页面。
答案 0 :(得分:2)
您的表单将覆盖操作属性中的查询字符串参数。
添加查询字段而不是将查询字符串放入操作中
<form class="filter_form" method="get" action="index.php">
<!-- ... the rest of your form code -->
<input class="button filter_button" type="submit" value="filter" />
<input type="hidden" name="page" id="page" value="agenda" />
</form>
相关帖子:submitting a GET form with query string params and hidden params disappear
答案 1 :(得分:2)
您应该在表单中使用隐藏的输入元素,而不是在URL中添加参数:
Sub updateoverdue()
Application.ScreenUpdating = True
Dim j As Long, i As Long, lastRow1 As Long, lastRow2 As Long
Dim sh_1, sh_3 As Worksheet
Set sh_1 = Sheet6
Set sh_3 = Sheet6
lastRow1 = sh_1.UsedRange.Rows.Count
For j = 2 To lastRow1
Sheet6.Range("z1") = sh_1.Cells(j, 9).Value
lastRow2 = sh_3.UsedRange.Rows.Count
For i = 2 To lastRow2
If sh_3.Cells(i, 9).Value < Sheet6.Range("z1") And sh_3.Cells(i, 10).Value = "Issued" Then
sh_3.Cells(i, 10).Value = "Overdue"
End If
Next i
Next j
Application.ScreenUpdating = True
End Sub
答案 2 :(得分:0)
您应该在表单中添加一个隐藏的输入字段。而是将其附加到操作字符串中,
<input type="hidden" name="page" value="agenda" />
答案 3 :(得分:0)
添加隐藏字段:
<input type="hidden" name="page" value="agenda" />
您的操作中的get参数被“ GET”方法取代。