Technex Posted July 16, 2007 Share Posted July 16, 2007 On my website I have a code like this where if $thispage='test'; then it would echo in the page title "(Ti|test". I have this for index.php $action = $_GET['action']; if ($action==NULL){ $thispage="Homepage"; } Which works fine. but say for ?action=members this should work right? $action = $_GET['action']; if ($action==members){ $thispage="Members"; } But all it outputs in page title is nothing like this: "(Ti|" Quote Link to comment Share on other sites More sharing options...
dooper3 Posted July 16, 2007 Share Posted July 16, 2007 Firstly, when doing "if", "else" statements, the only time you don't use quote marks around the bit you're asking if it looks like - in this case "members", is if it's an interger (a number). Otherwise it should always have quote marks. Therefore the code should read: $action=$_GET['action']; if ($action=="members") { $thispage="Members"; } But if I were you, i'd lose the $action=$_GET['action'] line, unless you refer to $action more in the file, as it's just a wasted line. So that would leave... if ($_GET['action']=="members") { $thispage="Members"; } If you find this isn't working, then it's probably a problem with the $_GET['members'] variable (try just echoing it and see what it says to ensure you're spelling it right etc.). Quote Link to comment Share on other sites More sharing options...
Technex Posted July 16, 2007 Author Share Posted July 16, 2007 Yeah it didn't work... echo $_GET['members']; shows nothing. But it does actually show the member list. if ($_GET['action']=="members") { $thispage="Members"; } doesn't work also. Thanks still. Quote Link to comment Share on other sites More sharing options...
dooper3 Posted July 16, 2007 Share Posted July 16, 2007 Sorry, I meant try echo $_GET['action']; not echo $_GET['members']; silly me! That wouldn't work. Tell me what it says when you do that one. Quote Link to comment Share on other sites More sharing options...
Technex Posted July 16, 2007 Author Share Posted July 16, 2007 Hehe okay. It gives out this: members Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted July 16, 2007 Share Posted July 16, 2007 if there are a lot of values 'action' can take then a switch would be better switch(trim($_GET['action'])) { case 'members': $thispage="Members"; break; case 'freaks': $thispage="Cook Book"; break; case 'noodles': $thispage="Cannibalism for Beginners"; break; default: $thispage="Soft Porn Extravaganza!"; } Quote Link to comment Share on other sites More sharing options...
dooper3 Posted July 16, 2007 Share Posted July 16, 2007 The man has a point. Also, going back to the original method aswell. If the echo is showing that $_GET['action'] has a value "members", then the... if ($_GET['action']=="members") { $thispage="Members"; } Should work, and perhaps it's the other part of the page that isn't. To test it out, try adding this line under the above part. echo $thispage; If the if statement is working, it should come out with "Members" somewhere. Quote Link to comment Share on other sites More sharing options...
Technex Posted July 16, 2007 Author Share Posted July 16, 2007 Whereas that case code is used elsewhere in my site, I don't think it's the right in this case, it seems like bloted code. Unless I can just add this to index.php and be done with it? echo $thispage; = Members @ dooper So it should work! Thanks for the help guys . Quote Link to comment Share on other sites More sharing options...
Technex Posted July 17, 2007 Author Share Posted July 17, 2007 Bump, thank you guys/gals . I'll try the case method now but I don't think it'll work. /edit. I got it to work, I thought as the index.php is always included why not just use it there. It works . Thanks guys, I'll put the case method in anyway as it's faster correct? (as it's now on one page) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.