John
John

Reputation: 1

Using PHP Get function to show content on webpage, yet still using same PHP file?

I'm new to PHP, and just creating a simple website.

At the moment, I have a header with some links (i.e. blog, faq, home, gaming etc). I'm trying to use GET functions to show new content in a container on the webpage. I've tried having them link to the index and to a specific page, like

<a href="?page=home">Home</a>

and then having some PHP in the html body...

<?php
if ($_GET[page] == "faq") {
   $result === 'FAQ';
} else {
$result === 'Non-FAQ';
}
echo $result;
?>

just to see if it would work, and lo and behold, it doesn't.

So, that's basically the gist of what's happening. It's baffled me for the past few hours, and would really appreciate some help

Thanks

Upvotes: 0

Views: 118

Answers (2)

Marco Johannesen
Marco Johannesen

Reputation: 13134

<?php
if ($_GET[page] === "faq") {
   $result = 'FAQ';
} else {
   $result = 'Non-FAQ';
}
echo $result;
?>

If you want to DEFINE a string you use one "=", if you want to compare it you use "===" (or ==) :)

Upvotes: 0

Phil
Phil

Reputation: 164895

You aren't using the assignment operator to assign a value to $result. Use a single equals sign, ie

<?php
if ($_GET['page'] == "faq") {
   $result = 'FAQ';
} else {
   $result = 'Non-FAQ';
}
echo $result;
?>

Upvotes: 1

Related Questions