0

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

Pagination

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

1"

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!

Martijn
  • 15,791
  • 4
  • 36
  • 68

3 Answers3

3

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 ).'"';
                ^
Martijn
  • 15,791
  • 4
  • 36
  • 68
1

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) . '"';
Ayame__
  • 980
  • 2
  • 9
  • 21
0

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?

Community
  • 1
  • 1
user2226755
  • 12,494
  • 5
  • 50
  • 73
  • Actually, there's no error in that in his code. $_GET variables are all strings, and in his code he compares to string 3 (`"3"`). Typechecking has no added value here, but it's no wrong – Martijn Feb 26 '14 at 11:30