2014-02-26 11:13

使用$ _GET进行分页,添加一个


So what i am doing is creating a pagination in one php file.

i'm using $_GET for this:

if ( $_GET["page"] === "3" ) echo 'href="#"';
else echo 'href=?page=' . $_GET["page"] + 1 . '"';

This code is used for making the side arrow's work


when i am on ?page=3 the script echo's href"#" like expected, but when i am on every other page the script echos


I have checked the script a few times and don't see any error's.

I think i am just doing something stupid, but I really don't know what.

I hope you want to help me!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • donglisi8644 donglisi8644 7年前

    You're adding a string and an integer with "+" inside a concat with no parenthesis

    change it to

    if ( $_GET["page"] === "3" ) echo 'href="#"'; else echo 'href="?page=' . ($_GET["page"]+ 1) . '"';
    点赞 评论 复制链接分享
  • duanba2001 duanba2001 7年前

    Didn't use "===", if $_GET["page"] is int your code return false. And you forget one quote.

    Try this :

    echo 'href="'.( ($_GET["page"] == 3) ? '#' : '?page='.($_GET["page"]+1) ).'"';

    Read this : How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?

    点赞 评论 复制链接分享
  • dqdz6464 dqdz6464 7年前

    Your else is wrong with the quotes and you need the brackets around the +1:

    else echo 'href=?page=' . $_GET["page"] + 1 . '"';
    // should be
    else echo 'href="?page='.( $_GET["page"] + 1 ).'"';
    点赞 评论 复制链接分享