Hepp Posted February 6, 2008 Share Posted February 6, 2008 To answer your question, yes I read the FAQs, and there was a Select Case example there. I've been coding for 3+ years now, but this is angering me. Snippet of code: <?php function aboutUs($page) { echo "This is the <b>about</b> section."; } if (isset($_GET['page'])) { $page = ($_GET['page']); if ($page[0] == "aboutUs") { aboutUs(); } else { echo ""; } } ?> <a href=static.php?page=aboutUs>About</a> I've been trying to get that to work all day. Is there something I am overlooking, doing wrong, or forgetting? Bleh I need sleep Thanks so much. -Hepp Quote Link to comment https://forums.phpfreaks.com/topic/89751-solved-if-statement-_get-var-links-with-functions/ Share on other sites More sharing options...
pocobueno1388 Posted February 6, 2008 Share Posted February 6, 2008 You never told us what you were trying to do, or what the problem was. Quote Link to comment https://forums.phpfreaks.com/topic/89751-solved-if-statement-_get-var-links-with-functions/#findComment-459924 Share on other sites More sharing options...
Hepp Posted February 6, 2008 Author Share Posted February 6, 2008 Hey man, thanks for replying. I quickly threw it in the title - apologies. I'm trying to have a page, and when the link is clicked (bottom of code), it pulls out the function using $_GET because I'm looking to make many of these. And the problem is that the text doesn't appear from the function when the link is clicked. Thanks. -Hepp Quote Link to comment https://forums.phpfreaks.com/topic/89751-solved-if-statement-_get-var-links-with-functions/#findComment-459926 Share on other sites More sharing options...
haku Posted February 6, 2008 Share Posted February 6, 2008 I still don't really get what your problem is. But I see a couple problems: 1) you are referring to $page both as a single variable, and then as an array later on. 2) The function aboutUs($page) calls for the variable $page, but you aren't passing it to the function when you call it. Don't know if thats where your problem is, but y8ou can try to fix those things and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/89751-solved-if-statement-_get-var-links-with-functions/#findComment-459930 Share on other sites More sharing options...
Hepp Posted February 6, 2008 Author Share Posted February 6, 2008 I still don't really get what your problem is. Don't know if thats where your problem is, but y8ou can try to fix those things and see what happens. The problem is that when you click the link, it does not display the code from the function like I've been trying to get it to, you know? 2) The function aboutUs($page) calls for the variable $page, but you aren't passing it to the function when you call it. But the function calling the variable, I removed it. I tried something earlier, forgot to get rid of it. Here's the revised code: <?php function aboutUs() { echo "This is the <b>about</b> section."; } if (isset($_GET['page'])) { $page = ($_GET['page']); if ($page[0] == "aboutUs") { aboutUs(); } else { echo ""; } } ?> <a href=static.php?page=aboutUs>About</a> 1) you are referring to $page both as a single variable, and then as an array later on. Can you not refer to $page as a single and then to an array? I couldn't think of another way to do this. Thanks man. -Hepp Quote Link to comment https://forums.phpfreaks.com/topic/89751-solved-if-statement-_get-var-links-with-functions/#findComment-459942 Share on other sites More sharing options...
kenrbnsn Posted February 6, 2008 Share Posted February 6, 2008 You want the "if" statement to be <?php if ($page == "aboutUs") { aboutUs(); } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/89751-solved-if-statement-_get-var-links-with-functions/#findComment-459948 Share on other sites More sharing options...
Hepp Posted February 6, 2008 Author Share Posted February 6, 2008 Ken, I LOVE YOU. THANK YOU. So simple, yet I need sleep. Thanks buddy. Revised correct code for anyone who is looking: <?php function aboutUs() { echo "This is the <b>about</b> section.<p>"; } function otherPage() { echo "This is the <b>other</b> section.<p>"; } if (isset($_GET['page'])) { $page = ($_GET['page']); if ($page == "aboutUs") { aboutUs(); } elseif ($page == "otherPage") { otherPage(); } else { echo ""; } } ?> <a href=static.php?page=aboutUs>About</a> <a href=static.php?page=otherPage>Other</a> Thanks again Ken =) -Hepp Quote Link to comment https://forums.phpfreaks.com/topic/89751-solved-if-statement-_get-var-links-with-functions/#findComment-459960 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.