dongmu5596 2014-10-30 10:51
浏览 32
已采纳

PHP分页值错误

I get errors: Notice: Undefined index: p, page, srt and 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

And also on: Notice: Undefined index: category, description,model,cond,location,photos,featured and where

$_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;

Any Help please?

  • 写回答

3条回答 默认 最新

  • duanaoshu1989 2014-10-30 10:56
    关注

    In your URL, do you have parameters such as http://www.yoursite.com/yourpage.php?p=XXX&page=YYYY&srt=ZZZZ ?

    If those parameters are optionnal, use:

    if (!isset($_GET["p"])) $_GET["p"] = $conf["perpage"];
    

    But actually, a better practice is to not assign $_GET by yourself. Instead, set a variable and use it later instead of using $_GET content:

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

    If you are doing a redirection in your htaccess, make sure to forward the GET parameters using [QSA].

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?