Jump to content

Archived

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

ItsWesYo

Else/elseif

Recommended Posts

Recently, I asked my friend if he knew a php code where I could add other pages into the page or whatever. He told me to use elseif and such. Well, I want to have a php script inside it, but it comes up with errors. Here is the whole page code. For the example, I'll use my [b]about.php[/b] code.

[code]
<?php
include ("http://www.evermoreforums.com/wes/header.php");
$page = $_REQUEST['page'];

if($page == "basics"){
echo ( "

blah, content goes here

" );
die();
}


elseif($page == "likes"){
echo ( "

blah, other content goes here

" );
die();
}


elseif($page == "dislikes"){
echo ( "

other content goes here, again

" );
die();
}


else {
echo ( "

this is the page that shows up as 'about.php'
like, the "main" page

");
die();
}



?>
[/code]

Share this post


Link to post
Share on other sites
A better way to do it might be use includes:

[code]
<?php
include ("http://www.evermoreforums.com/wes/header.php");
$page = $_REQUEST['page'];
if($page == "basics")
{
include("basics.php");
}
elseif($page == "likes")
{
include("likes.php");
}else{
include("defaultpage.php");
[/code]

If you do it like this, you can avoid having a massive file.

Share this post


Link to post
Share on other sites
Here's it nicely wrapped up. PS, you should include a foreign file "http:// etc.." many PHP systems will have it blocked anyway. You should include it locally like [b]include("/wes/header.php");[/b]

Here's the code:
[code]
<?php
include ("http://www.evermoreforums.com/wes/header.php");
$page = ((isset($_REQUEST['page']))?($_REQUEST['page']):(''));

switch($page)
{
        case "basics":
        {
                echo ( "blah, content goes here" );
                break;
        }
        case "likes":
        {
                echo ( "blah, content goes here" );
                break;
        }
        case "dislikes":
        {
                echo ( "blah, content goes here" );
                break;
        }
        default:
        {
                echo ( "this is the page that shows up as 'about.php'like, the main page");
                break;
        }
}
?>
[/code]

Share this post


Link to post
Share on other sites
Ah yes, a switch statement is probably better here...i always seem to forget about those.

Share this post


Link to post
Share on other sites
Sorry for bumping this, but I needed a change of plans for something.

For ShogunWarrior's code, how would I include a page in the code?

Share this post


Link to post
Share on other sites
Instead of the [b]echos[/b] e.g: echo('Content');
Replace them with an include of another page you have created: [b]include('content.php');[/b]

Share this post


Link to post
Share on other sites
you can but it's not necessary on includes, without how many you end up using it's easies
include 'url';
automatically includes, it's faster if you use a lot of includes
also in the url sometimes in php.ini it has a prefix, if so you ALWAYS have to put a
./ in front of the url
and ../ if it's 2 levels feep

Share this post


Link to post
Share on other sites

×

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.