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
https://forums.phpfreaks.com/topic/14374-elseelseif/
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
https://forums.phpfreaks.com/topic/14374-elseelseif/#findComment-56704
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
https://forums.phpfreaks.com/topic/14374-elseelseif/#findComment-56706
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
https://forums.phpfreaks.com/topic/14374-elseelseif/#findComment-65467
Share on other sites

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.