【发布时间】:2013-02-15 15:00:10
【问题描述】:
$_GET 数组有问题。在我的页面上,一个值来自这样的 URL。
http://localhost/search.php?subject=Mathematics
我检查这个 $_GET 值是这样的..
// Check for a valid keyword from search input:
if ( (isset($_GET['subject'])) && (is_string ($_GET['subject'])) ) { // From SESSION
foreach ( $_GET AS $key => $subject) {
$searchKey = $key;
$searchKeyword = '%'.$subject.'%';
}
} else { // No valid keyword, kill the script.
echo 'This page has been accessed in error.';
include ('includes/footer.html');
exit();
}
现在它为我工作。但我的问题是我正在使用另外两个变量通过同一页面上的 URL 来过滤我的数据库值。
echo '<li><a href="?tutor=link">Tutor</a></li>
<li><a href="?institute=link">Institute</a></li>';
这两个链接我用来过滤我的数据库值(单击此链接)。
$tutor = isset($_GET['institute']) ? '0' : '1';
$institute = isset($_GET['tutor']) ? '0' : '1';
我的问题是,当我尝试过滤数据库结果时,单击上面的链接它总是使用此代码,而不是显示过滤结果。
} else { // No valid keyword, kill the script.
echo 'This page has been accessed in error.';
include ('includes/footer.html');
exit();
}
谁能告诉我如何使用这 3 个 $_GET 值。
【问题讨论】:
-
为什么不用两个查询参数?
target=tutor&link=...?这减少了您检查$_GET['target']是否包含有效内容的工作,而不必检查三个不同的可能 $_GET 值。