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
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!
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) . '"';
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 ).'"';
^
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?