Jump to content

Else/elseif


ItsWesYo

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]

Link to comment
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.
Link to comment
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]
Link to comment
Share on other sites

  • 3 weeks later...
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
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.