Log in

View Full Version : PHP Includes.



iRoss
16-06-2005, 04:08 PM
Hey.

Im having trouble with these PHP includes i know where to put the codes and stuff.

But i don't understand that " Case " Tag.

If you could explain the whole lot fully it would help :)

Thanks.

Ross

Mentor
16-06-2005, 05:12 PM
Umm case tag?

php include all you need is.



<?php
include("somepage.htm");
?>

Mentor
16-06-2005, 05:15 PM
php include all you need is.



<?php
include("somepage.htm");
?>


Unless you mean one of the navigation systems, in wich it uses the case; tags to check for varibles etc.

Athogh i personly find it far easyer just to use teh if tags

aka


<?php
// get variable from url
$item = basename($item);

// include pages depedning on if statement
if($item == "pie") { include("piepage.htm"); }
elseif($item == "cheese") { include("chessepage.htm"); }
elseif($item == "cake") { include("mmmcake.htm"); }
// if doesnt fit above go to this
else { include("default.htm"); }

?>


Edit by Urges - Please refrain from double posting. Simply edit your first one. Thankyou

iRoss
16-06-2005, 08:42 PM
So you don't have to use the case tag?

And could you explain the above post in more detail please? :)

Mentor
16-06-2005, 09:46 PM
the good thing about php is theres usealy 3 or 4 ways of doing evrerything,
case tags, if tags, (there is another one ive curantly forgotten)

case tags is more confusing than the if tag, wich does quite litral what it says

Ok, lets say a url to the page the below code is on is index.php?page=this

To get the value of page, in to a variable


$page = basename($page);


Then the if statemnte comes in




if($page=="cake")
{ echo "mmm cake"; }


So splitting it up.

if($page=="cake");

Says if the varible page, holds the infomation cake . then it does whats between the {} tags after it, in this case echo out "mmmm cake"

Then, to test for another possiblty in the same bit, you use the else if, wich is an exstntion on this if tag



elseif($page == "pie") {echo "pie rules"; }


wich works in the same way as the if more aless, and can be used as many times as you like.

so for exsample



elseif($page == "wood") {echo "wood like it is"; }
elseif($page == "stone") {echo "seems rocky"; }
elseif($page == "egg") {echo "makes a meal out of anything"; }



Once you have all the possibltys you want, the you ad the end bit the else tag



else {"ok i give up " ;}



which basicaly says, if non of the above match, use this.

And thats more aless the whole of the if statment, with a basic use, you could include pages insted of echoing random comments for exsample.

hope that helps.

and here the full useless script here


$page = basename($page);

if($page=="cake") { echo "mmm cake"; }

elseif($page == "pie") {echo "pie rules"; }
elseif($page == "wood") {echo "wood like it is"; }
elseif($page == "stone") {echo "seems rocky"; }
elseif($page == "egg") {echo "makes a meal out of anything"; }

else {"ok i give up " ;}

Rix
17-06-2005, 11:05 AM
how do you had php to a page on frontpage

iRoss
17-06-2005, 02:22 PM
the good thing about php is theres usealy 3 or 4 ways of doing evrerything,
case tags, if tags, (there is another one ive curantly forgotten)

case tags is more confusing than the if tag, wich does quite litral what it says

Ok, lets say a url to the page the below code is on is index.php?page=this

To get the value of page, in to a variable


$page = basename($page);


Then the if statemnte comes in




if($page=="cake")
{ echo "mmm cake"; }


So splitting it up.

if($page=="cake");

Says if the varible page, holds the infomation cake . then it does whats between the {} tags after it, in this case echo out "mmmm cake"

Then, to test for another possiblty in the same bit, you use the else if, wich is an exstntion on this if tag



elseif($page == "pie") {echo "pie rules"; }


wich works in the same way as the if more aless, and can be used as many times as you like.

so for exsample



elseif($page == "wood") {echo "wood like it is"; }
elseif($page == "stone") {echo "seems rocky"; }
elseif($page == "egg") {echo "makes a meal out of anything"; }



Once you have all the possibltys you want, the you ad the end bit the else tag



else {"ok i give up " ;}



which basicaly says, if non of the above match, use this.

And thats more aless the whole of the if statment, with a basic use, you could include pages insted of echoing random comments for exsample.

hope that helps.

and here the full useless script here


$page = basename($page);

if($page=="cake") { echo "mmm cake"; }

elseif($page == "pie") {echo "pie rules"; }
elseif($page == "wood") {echo "wood like it is"; }
elseif($page == "stone") {echo "seems rocky"; }
elseif($page == "egg") {echo "makes a meal out of anything"; }

else {"ok i give up " ;}



Ok. But why does it have to echo ?

Mentor
17-06-2005, 03:41 PM
Ok. But why does it have to echo ?


echo basicly is just the function that tellls it to write to the page, aka

echo "<b> Hello </b>";

woudl just write on to the html page

<b> Hello </b>

echo, basicly prints the data.

so it doesnt actaly have to be echo, you could put any other bit of php in the gaps to do, you could even ad another if statement if you wanted. or an include, for a navigation, or seting a varible, what ever you wanted realy. i just used the echo statemnte for the exsample



how do you had php to a page on frontpage


front page is prettyy crapy, and i dont think it supports php, easyest just to do in notepad, as you cant get a proper visula pic of it anyway as it would need to genorate.

then just save as the file .php , but in note pad put that in "" quote marks, so it chnages the file type rather than adding .txt to the end of it

iRoss
17-06-2005, 04:04 PM
So if you leave the echo bits blank ( Because i don't really understand them ) Would it matter?

Mentor
17-06-2005, 04:06 PM
well the if statment would work, but when it came to the bits nothing would appear since theres nothing telling php to write anything

iRoss
17-06-2005, 04:08 PM
What. So you would have to put all the php that you want to appear on that page in the {echo "pie rules"; } bit?

Want to hide these adverts? Register an account for free!