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
Printable View
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
Umm case tag?
php include all you need is.
PHP Code:<?php
include("somepage.htm");
?>
Unless you mean one of the navigation systems, in wich it uses the case; tags to check for varibles etc.Quote:
Originally Posted by Mentor
Athogh i personly find it far easyer just to use teh if tags
aka
Edit by Urges - Please refrain from double posting. Simply edit your first one. ThankyouPHP Code:<?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"); }
?>
So you don't have to use the case tag?
And could you explain the above post in more detail please? :)
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
Then the if statemnte comes inPHP Code:$page = basename($page);
So splitting it up.PHP Code:
if($page=="cake")
{ echo "mmm cake"; }
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
wich works in the same way as the if more aless, and can be used as many times as you like.PHP Code:elseif($page == "pie") {echo "pie rules"; }
so for exsample
Once you have all the possibltys you want, the you ad the end bit the else tagPHP Code:elseif($page == "wood") {echo "wood like it is"; }
elseif($page == "stone") {echo "seems rocky"; }
elseif($page == "egg") {echo "makes a meal out of anything"; }
which basicaly says, if non of the above match, use this.PHP Code:else {"ok i give up " ;}
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
PHP Code:$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 " ;}
how do you had php to a page on frontpage
Quote:
Originally Posted by Mentor
Ok. But why does it have to echo ?
Quote:
Originally Posted by iRoss
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
Quote:
Originally Posted by phoenix-iv
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
So if you leave the echo bits blank ( Because i don't really understand them ) Would it matter?
well the if statment would work, but when it came to the bits nothing would appear since theres nothing telling php to write anything