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|" Link to comment https://forums.phpfreaks.com/topic/60171-if-actionmembersthispagemembers-problem-please-help/ 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.). Link to comment https://forums.phpfreaks.com/topic/60171-if-actionmembersthispagemembers-problem-please-help/#findComment-299350 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. Link to comment https://forums.phpfreaks.com/topic/60171-if-actionmembersthispagemembers-problem-please-help/#findComment-299358 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. Link to comment https://forums.phpfreaks.com/topic/60171-if-actionmembersthispagemembers-problem-please-help/#findComment-299368 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 Link to comment https://forums.phpfreaks.com/topic/60171-if-actionmembersthispagemembers-problem-please-help/#findComment-299372 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!"; } Link to comment https://forums.phpfreaks.com/topic/60171-if-actionmembersthispagemembers-problem-please-help/#findComment-299374 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. Link to comment https://forums.phpfreaks.com/topic/60171-if-actionmembersthispagemembers-problem-please-help/#findComment-299379 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 . Link to comment https://forums.phpfreaks.com/topic/60171-if-actionmembersthispagemembers-problem-please-help/#findComment-299686 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) Link to comment https://forums.phpfreaks.com/topic/60171-if-actionmembersthispagemembers-problem-please-help/#findComment-300375 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.