Jump to content


few questions


13 replies to this topic

#1 TheUnforgiven512

    Young Padawan

  • Members
  • Pip
  • 102 posts

Posted 10 March 2006 - 01:01 PM

How do I set up the ? in the codes? Maybe I should tell you what I want to do. I need to make a website that has 20 links and occurs on several pages. Then those links have sub-links. If I can not use an iframe/frame or anything other than that, is it possible to have all the links in one php file and that would be imported? because if I did not have those in any seperate file, I would have to edit the links for evey page. it could even be a typo one link but I would have to change it in about 300 html files maybe. so is there a way to import links using php into a website?

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 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 10 March 2006 - 01:25 PM

for the ? part, use a switch statement. but first lets explain something about the links.

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 TheUnforgiven512

    Young Padawan

  • Members
  • Pip
  • 102 posts

Posted 10 March 2006 - 01:34 PM

Awsome thanks man! ill try it later on and tell you how it goes. Thanks so much

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 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 10 March 2006 - 02:43 PM

it can be any type of file, including .php
heh... it can even be a .txt file and still work the same.

#5 TheUnforgiven512

    Young Padawan

  • Members
  • Pip
  • 102 posts

Posted 10 March 2006 - 02:48 PM

and im guessing the html code needs to be in quotes?

#6 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 10 March 2006 - 03:20 PM

no it doesnt, personaly i hate the way you have done that, there is no need to mix the php with the html there, a better way for it to be done is by:
<?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 Chaos King

    Senior Programmer

  • P2L Staff
  • PipPipPip
  • 676 posts
  • Gender:Male
  • Location:Florida

Posted 10 March 2006 - 04:26 PM

I will give you props for the simple tutorial, pretty simple and it explains the important details, but if he has a modern host, he may ask: "Why does it not work?" This is why. :)

<?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. :D

Edited by Chaos King, 10 March 2006 - 04:26 PM.


#8 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 10 March 2006 - 04:44 PM

To be honest, I hate switch statements. Make a different page for every link.
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 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 10 March 2006 - 05:11 PM

that up there is just abnormal practice :)

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 TheUnforgiven512

    Young Padawan

  • Members
  • Pip
  • 102 posts

Posted 10 March 2006 - 05:46 PM

yeah I want the php file to contain all the links and sublinks. so there will be only one php file and I dont want to make 20 or 30

#11 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 10 March 2006 - 06:02 PM

then you want to be using my example

#12 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 10 March 2006 - 06:51 PM

View Postdeadly, on Mar 10 2006, 11:02 PM, said:

then you want to be using my example
mines and yours example are both the same, except with your method, he'd have a new page for every case, he dont want that.
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 TheUnforgiven512

    Young Padawan

  • Members
  • Pip
  • 102 posts

Posted 10 March 2006 - 08:06 PM

yeah I dont want to make a seperate php file for every sub link category so i find your method the best for what I need to do coolaid.

#14 TheUnforgiven512

    Young Padawan

  • Members
  • Pip
  • 102 posts

Posted 11 March 2006 - 04:26 PM

sweet it works so far. Thank you all so much. Ill post if I have any problems with it.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users