Jump to content

if ($action==members){$thispage="Members";} Problem, please help :).


Technex

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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