...

View Full Version : Resolved Get variable for URL



RonnyNishimoto
08-03-2012, 06:46 AM
<? if($_GET['m'] == "page1" || !isset($_GET['m'])){ ?>
a
<? }
else if($_GET['m'] == "page2"){ ?>
b
<? } ?>


:confused: It's not working :[

I was trying to have different "pages" in a single php file, but it doesn't seem to be working. If I'm doing this the wrong way, let me know!

Arcticwarrio
08-03-2012, 09:33 AM
<? if($_GET['m'] == "page1" || !isset($_GET['m'])){ ?>
a
<? }
else if($_GET['m'] == "page2"){ ?>
b
<? } ?>


:confused: It's not working :[

I was trying to have different "pages" in a single php file, but it doesn't seem to be working. If I'm doing this the wrong way, let me know!

first <? is frowned upon please use <?PHP instead,
you need to wrap each if in brackets, then the whole if in brackets:



<?PHP
if (($_GET['m'] == "page1") || (!isset($_GET['m']))) {
echo "a";
}
else if ($_GET['m'] == "page2"){
echo "b";
}
?>

Arcticwarrio
08-03-2012, 09:38 AM
also if you have a few pages you want to use, consider using switch instead:



<?PHP
switch ($_GET['m']){

case 'page1':
echo "a";
break;

case 'page2':
echo "b";
break;

case 'page3':
echo "c";
break;

default:
//w what to do if $_GET['m'] isnt set

}
?>

RonnyNishimoto
08-03-2012, 10:28 AM
It worked!

I copy code from tutorials and often times they are wrong lol...

Dormilich
08-03-2012, 11:49 AM
I copy code from tutorials and often times they are wrong
the human error, also called low quality. if Id find a tutorial to be either out of date or containing errors, Id discard it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum