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

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

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.

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.