Jump to content


Photo

Else/elseif


  • Please log in to reply
9 replies to this topic

#1 ItsWesYo

ItsWesYo
  • Members
  • PipPipPip
  • Advanced Member
  • 110 posts

Posted 12 July 2006 - 10:50 AM

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 about.php 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();
}



?>



#2 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 12 July 2006 - 10:55 AM

A better way to do it might be use includes:

<?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");

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

#3 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 12 July 2006 - 10:57 AM

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 include("/wes/header.php");

Here's the 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;
        }
}
?>

<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#4 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 12 July 2006 - 10:58 AM

Ah yes, a switch statement is probably better here...i always seem to forget about those.

#5 ItsWesYo

ItsWesYo
  • Members
  • PipPipPip
  • Advanced Member
  • 110 posts

Posted 12 July 2006 - 11:40 AM

So can I use php scripts inside in those pages too?

#6 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 12 July 2006 - 04:52 PM

Yes, you include a php file.

#7 ItsWesYo

ItsWesYo
  • Members
  • PipPipPip
  • Advanced Member
  • 110 posts

Posted 28 July 2006 - 05:06 PM

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?

#8 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 28 July 2006 - 05:25 PM

Instead of the echos e.g: echo('Content');
Replace them with an include of another page you have created: include('content.php');
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#9 ItsWesYo

ItsWesYo
  • Members
  • PipPipPip
  • Advanced Member
  • 110 posts

Posted 28 July 2006 - 05:42 PM

Ah, thanks once again.

#10 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 10:25 PM

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

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users