Jump to content

[SOLVED] If Statement $_GET Var Links With Functions


Hepp

Recommended Posts

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  :P

 

Thanks so much.

-Hepp

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.