我正在尝试在某处实现分页,但我遇到了这个问题:
我有这部分来更改链接:
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
这给出了这部分的错误:
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
它说未定义的索引..为什么会出现此错误?谢谢
我正在尝试在某处实现分页,但我遇到了这个问题:
我有这部分来更改链接:
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
这给出了这部分的错误:
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
它说未定义的索引..为什么会出现此错误?谢谢
You should quote the array index. also use html entities. Like this
echo " <a href='{$_SERVER['SCRIPT_NAME']}?Page=$Prev_Page'><< Back</a> ";
And its safe to check if $_GET["Page"]
exists.
$Page = isset($_GET["Page"]) ? $_GET["Page"]: false;
This happens because you are missing an index in the array. $_GET is just an array, so you should check if the key exists first.
$Page = (array_key_exists('page', $_GET)) ? $_GET["page"] : false;
if($Page===false)
{
//no page
return;
}
// empty() works even if the variable doesn't exist, kind of like isset()
if(!empty($_GET['Page']) !== false) {
// Do stuff
$page = $_GET['Page'];
}