PHP分页值错误

PHP分页值错误,php,Php,我发现错误: 注意:未定义索引:p、page、srt和where // set default pagenation values if(!$_GET['p']) $_GET['p'] = $conf['perpage']; // default number of entries per page if(!$_GET['page']) $_GET['page'] = 1; // current page if(!$_GET['srt']) $_GET['srt'] = $conf[

我发现错误: 注意:未定义索引:p、page、srt和where

    // set default pagenation values
if(!$_GET['p']) $_GET['p'] = $conf['perpage']; // default number of entries per page
if(!$_GET['page']) $_GET['page'] = 1; // current page
if(!$_GET['srt']) $_GET['srt']   = $conf['srt']; // default sort order
$start = ($_GET['page'] - 1) * $_GET['p']; // start row for query

// get total number of entries for pagenation
$result = mysql_query("SELECT COUNT(*) FROM articals $where", $link);
$total  = mysql_fetch_array($result); $total = $total[0]; // total number of listings
$pages  = ceil($total / $_GET['p']); // number of pages
$_GET = safe_data($_GET, 'query');

if($_GET['category']) $where .= "AND (category='$_GET[category]' OR category2='$_GET[category]') ";
if($_GET['description']) $where .= "AND description LIKE '%$_GET[description]%' ";
if($_GET['model']) $where .= "AND model LIKE '%$_GET[model]%' ";
if($_GET['cond']) $where .= "AND cond='$_GET[cond]' ";


if($_GET['location']) $where .= "AND location='$_GET[location]' ";
if($_GET['photos'])   $where .= "AND images>'0' ";
if($_GET['featured']) $where .= "AND featured='1' ";

// finialize query string if necessary
if(substr($where, 0, 3) == 'AND') {
    $where = ltrim($where, 'AND');
    $where = 'WHERE'.$where;
}

// do not show hidden and expired listings
 $display = "hide!='1' AND (expire>'".time()."' OR expire='' OR expire='0') AND (user_expire>'".time()."' OR user_expire='' OR user_expire='0')";
$display = "hide!='1'";
if(!$where) $where = "WHERE ".$display;
else $where .= "AND ".$display;

以及: 注意:未定义索引:类别、描述、型号、条件、位置、照片、特色和位置

    // set default pagenation values
if(!$_GET['p']) $_GET['p'] = $conf['perpage']; // default number of entries per page
if(!$_GET['page']) $_GET['page'] = 1; // current page
if(!$_GET['srt']) $_GET['srt']   = $conf['srt']; // default sort order
$start = ($_GET['page'] - 1) * $_GET['p']; // start row for query

// get total number of entries for pagenation
$result = mysql_query("SELECT COUNT(*) FROM articals $where", $link);
$total  = mysql_fetch_array($result); $total = $total[0]; // total number of listings
$pages  = ceil($total / $_GET['p']); // number of pages
$_GET = safe_data($_GET, 'query');

if($_GET['category']) $where .= "AND (category='$_GET[category]' OR category2='$_GET[category]') ";
if($_GET['description']) $where .= "AND description LIKE '%$_GET[description]%' ";
if($_GET['model']) $where .= "AND model LIKE '%$_GET[model]%' ";
if($_GET['cond']) $where .= "AND cond='$_GET[cond]' ";


if($_GET['location']) $where .= "AND location='$_GET[location]' ";
if($_GET['photos'])   $where .= "AND images>'0' ";
if($_GET['featured']) $where .= "AND featured='1' ";

// finialize query string if necessary
if(substr($where, 0, 3) == 'AND') {
    $where = ltrim($where, 'AND');
    $where = 'WHERE'.$where;
}

// do not show hidden and expired listings
 $display = "hide!='1' AND (expire>'".time()."' OR expire='' OR expire='0') AND (user_expire>'".time()."' OR user_expire='' OR user_expire='0')";
$display = "hide!='1'";
if(!$where) $where = "WHERE ".$display;
else $where .= "AND ".$display;

有什么帮助吗?

您必须在每个get请求周围包装
isset()
,以消除通知

之所以显示此通知,是因为它们没有价值


您可以这样使用它:
if(isset($\u GET['p'])

此代码可能会帮助您,它包装了http php响应:

class Input {

    public static function Post($item,$default=null){
        //If the value was posted, then return that value, else return the $default value.
        return  isset($_POST[$item]) ? $_POST[$item] : $default;
    }

    public static function Get($item,$default=null){
        return  isset($_GET[$item]) ? $_GET[$item] : $default;
    }

    public static function Cookie($item,$default=null){
        return  isset($_COOKIE[$item]) ? $_COOKIE[$item] : $default;
    }

    public static function Param($item,$default=null){
        return self::Post($item) ?: self::Get($item) ?: self::Cookie($item) ?: $default;
    }

}
用法:

Input::Get('p',$conf['perpage']); // First argument is the index, second is default if not set.
在您的示例中:

$p = Input::Get('p',$conf['perpage']);
$page = Input::Get('page',1);
$srt= Input::Get('page',$conf['srt']);

$start = ($page - 1) *$p; // start row for query

在您的URL中,是否有以下参数

如果这些参数是可选的,请使用:

if (!isset($_GET["p"])) $_GET["p"] = $conf["perpage"];
但实际上,更好的做法是不要自己分配美元。相反,请设置一个变量并在以后使用它,而不是使用$\u GET content:

$p = (isset($_GET["p"])?$_GET["p"]:$conf["perpage"]);

如果您在htaccess中执行重定向,请确保使用[QSA]转发GET参数。

这意味着您的http请求在URL中没有
?p=[您的数据]
,如果(isset($\u GET['p'])可能与Handy重复,但
Param()
应使用
$\u request
,或者至少要尊重变量的顺序