few questions
#1
Posted 10 March 2006 - 01:01 PM
This brings me to my next question if the above is even possible. how would I seperate the links using the ? (mode or whatever that is) Example: links.php?cat=1 or links.php?cat=2. what part of the php code lets us make those criterias? any tutorials out there on this?
#2
Posted 10 March 2006 - 01:25 PM
its like this.
page.php?variable=value
so its just a page, and the first part is called a variable, the 2nd is a value.
now this is how the script would look.
<?
switch($_GET['variable']){
case "value1": ?>
THIS IS HTML CODE FOR VALUE1
<?
break;
case "value2": ?>
THIS IS HTML CODE FOR VALUE2
<?
break;
default: ?>
THIS IS THE DEFAULT VALUE (page.php)
<?
break;
}
?>
Edited by coolaid, 10 March 2006 - 01:25 PM.
#3
Posted 10 March 2006 - 01:34 PM
EDIT: also, can it be a php file if I am including it or does it have to be a tpl and all those other types?
Edited by TheUnforgiven512, 10 March 2006 - 01:44 PM.
#4
Posted 10 March 2006 - 02:43 PM
heh... it can even be a .txt file and still work the same.
#5
Posted 10 March 2006 - 02:48 PM
#6
Posted 10 March 2006 - 03:20 PM
<?php
switch ($page) {
default: include('content/home.php');
break; case "home": include('content/home.php');
break; case "about": include('content/about.php');
break; case "cartoons": include('content/cartoons.php');
break; case "jokes": include('content/jokes.php');
break; case "comments": include('content/comments.php');
break; case "links": include('content/links.php');
break; case "register": include('content/register.php');
break; case "contact": include('content/contact.php');
}
?>
Now to explain:case "contact": - the case you are defining is the part that goes in the link, e.g. index.php?page=contact - nice and simple.
include('content/contact.php') - simply including the page or file you want to be displayed
and the switch($page) at the top is just telling it which variable to use
and the links are set out in the same way - index.php?variable=case or index.php?page=contact
Any questions just ask me =)
#7
Posted 10 March 2006 - 04:26 PM
<?php
$page = $_GET['page'];
switch ($page) {
default: include('content/home.php');
break; case "home": include('content/home.php');
break; case "about": include('content/about.php');
break; case "cartoons": include('content/cartoons.php');
break; case "jokes": include('content/jokes.php');
break; case "comments": include('content/comments.php');
break; case "links": include('content/links.php');
break; case "register": include('content/register.php');
break; case "contact": include('content/contact.php');
}
?>
If you are coding, you need to code so that it will work in any envirnment.
Edited by Chaos King, 10 March 2006 - 04:26 PM.
#8
Posted 10 March 2006 - 04:44 PM
So say you had index.php?page=one
make a page called one.php
Then where you want the content to appear have
if (file_exists($_GET['one'].'.php')){
include($_GET['one'].'.php');
}else{
echo 'error! page not found';
}
Edited by Lang, 10 March 2006 - 04:45 PM.
#9
Posted 10 March 2006 - 05:11 PM
also, i figured he wanted to NOT include files (because he might as well just create seperate pages.....) so if he just wants to have html for each case, my eh.. style of code would be more suitable.
#10
Posted 10 March 2006 - 05:46 PM
#11
Posted 10 March 2006 - 06:02 PM
#12
Posted 10 March 2006 - 06:51 PM
deadly, on Mar 10 2006, 11:02 PM, said:
if he wants to add the code directly, my style is easier to use cause i seperate the breaks and cases accordingly instead of it all clumped togehter.
#13
Posted 10 March 2006 - 08:06 PM
#14
Posted 11 March 2006 - 04:26 PM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
