0

我正在尝试在某处实现分页,但我遇到了这个问题:

我有这部分来更改链接:

echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";  

这给出了这部分的错误:

$Page = $_GET["Page"];  
if(!$_GET["Page"])  
{  

它说未定义的索引..为什么会出现此错误?谢谢

4

3 回答 3

3

You should quote the array index. also use html entities. Like this

echo " <a href='{$_SERVER['SCRIPT_NAME']}?Page=$Prev_Page'>&lt;&lt; Back</a> "; 

And its safe to check if $_GET["Page"] exists.

$Page = isset($_GET["Page"]) ? $_GET["Page"]: false;
于 2012-12-17T15:37:35.557 回答
1

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;
}
于 2012-12-17T15:37:50.777 回答
0
// empty() works even if the variable doesn't exist, kind of like isset()
if(!empty($_GET['Page']) !== false) {
    // Do stuff
    $page = $_GET['Page'];
}
于 2012-12-17T15:41:26.053 回答