|
|
|
|
![]() ![]() |
Feb 28 2007, 08:43 PM
Post
#1
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 53 Joined: 24-February 07 From: Latvia Member No.: 39,133 |
Was just sitting and being bored but then I realized I could show how to create more or less popular ?id=page browsing.
It's actually really easy. I know two ways how to do it. First one I learned was checking the variable and if it's true including the text/file/anything needed and so on. It was ok, but sometimes I just couldn't make it work so I switched to switch() function and that's what I'm going to show you guys right now. So, I made a test page which contains the code needed and here is its source. CODE <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> </head> <body> <a href="?p=idx">Home</a> - <a href="?p=pagetwo">Page Two</a> - <a href="?p=pagethree">Page Three</a><br> <?php $page=$_GET['p']; switch($page){ default: echo 'This is the default page'; break; case 'pagetwo': echo 'This is page two'; break; case 'pagethree': echo 'This is page three<br>Cool, huh?'; } ?> </body> </html> Okies, I'll split up the code and explain it to you. I'll start with the links CODE <a href="?p=idx">Home</a> - <a href="?p=pagetwo">Page Two</a> - <a href="?p=pagethree">Page Three</a><br> Those are normal html links only their href leads to links like ?p= ...well replace p with letter or a word you want - mind that you can't put spaces there..well, maybe you can but..don't do that. Now for the PHP. CODE <?php $page=$_GET['p']; <?php starts php code $page=$_GET['p']; sets the $page variable to the page requested. Um, you have to change p in $_GET['p'] to word/letter you use for your links. $_GET gets the info from the url (in this tutorial CODE switch($page){ default: echo 'This is the default page'; break; case 'pagetwo': echo 'This is page two'; break; case 'pagethree': echo 'This is page three<br>Cool, huh?'; } switch($page){ Um, this part of code uses switch function to switch parts of code by using the $page variable. default: sets the default page that will be shown when user inputs an invalid url and the content that will be shown in index page. You see the echo() function in next line. You can input anything there...echo text/include file...use your imagination. Just put what you want to see in the default page. break; ends execution of the current switch structure. Can't really explain it but that. Ok, now for the part you want to see so bad. case 'pagetwo': ...see anything in common with the previous code I've shown? If you guessed <a href='?p=pagetwo'> then you are correct. If the $page variable is set to pagetwo switch function will switch the content to the content you will put after the colon. Same thing works for the rest of the code. You add a case'': checking for a variable, put the code to show it is true, use break to break the code and add next case. When you have added all the pages you want you just put a curved bracket (Like here I have done all my pages and want to end it. CODE case 'pagethree': ) and voila, your links are working.echo 'This is page three<br>Cool, huh?'; } Hope that helps you at least a little. Ask if you have any questions, corrections or suggestions. Oh, and here's the link to a preview. Cheers, Matt. This post has been edited by friiks: Mar 20 2007, 02:20 PM |
|
|
|
Mar 1 2007, 09:39 PM
Post
#2
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 53 Joined: 23-February 07 Member No.: 39,103 |
Cool dude, very useful.
When I used to go to 64Digits I always wondered how they used that system. Now, that you've used it on my site I was able to see the code and learned greatly from that. Very nice example, and I know everybody on this forum will agree when they get on to see it. This post has been edited by JDameron91: Mar 1 2007, 09:39 PM |
|
|
|
Mar 19 2007, 07:41 PM
Post
#3
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 299 Joined: 27-January 07 From: Winter is cold here. Member No.: 37,984 ![]() |
when i do it it turns up like this- Link. It says the same thing everytime I tried to do it. PLease help!
|
|
|
|
Mar 19 2007, 07:54 PM
Post
#4
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 53 Joined: 24-February 07 From: Latvia Member No.: 39,133 |
Show me the code you're using ,please!
|
|
|
|
Mar 19 2007, 08:06 PM
Post
#5
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 413 Joined: 4-October 06 From: Psychedelic Realms Member No.: 31,079 |
this code works for me...
CODE <a href="?p=idx">Home</a> - <a href="?p=pagetwo">Page Two</a> - <a href="?p=pagethree">Page Three</a><br>
<?php $page=$_GET['p']; switch($page){ default: echo 'This is the default page'; break; case 'pagetwo': echo 'This is page two'; break; case 'pagethree': echo 'This is page three<br>Cool, huh?'; } ?> |
|
|
|
Mar 19 2007, 08:08 PM
Post
#6
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 299 Joined: 27-January 07 From: Winter is cold here. Member No.: 37,984 ![]() |
this code works for me... CODE <a href="?p=idx">Home</a> - <a href="?p=pagetwo">Page Two</a> - <a href="?p=pagethree">Page Three</a><br> <?php $page=$_GET['p']; switch($page){ default: echo 'This is the default page'; break; case 'pagetwo': echo 'This is page two'; break; case 'pagethree': echo 'This is page three<br>Cool, huh?'; } ?> It displays this- QUOTE Home - Page Two - Page Three Cool, huh?'; } ?> On every page This post has been edited by Imtay22: Mar 19 2007, 08:09 PM |
|
|
|
Mar 19 2007, 08:20 PM
Post
#7
|
|
|
Incest is a game the whole family can play. ![]() Group: [MODERATOR] Posts: 1,223 Joined: 11-February 05 From: Heaven Member No.: 3,709 |
I don't know what the problem is but default: should always be the last case statement:
CODE <a href="?p=idx">Home</a> - <a href="?p=pagetwo">Page Two</a> - <a href="?p=pagethree">Page Three</a><br> <?php $page=$_GET['p']; switch($page){ case 'pagetwo': echo 'This is page two'; break; case 'pagethree': echo 'This is page three<br>Cool, huh?'; break; default: echo 'This is the default page'; } ?> Maybe that's the problem. |
|
|
|
Mar 19 2007, 09:31 PM
Post
#8
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 53 Joined: 24-February 07 From: Latvia Member No.: 39,133 |
Wow, I never knew that..
But anyways I've been always using it this way AND it has always worked.. |
|
|
|
Mar 20 2007, 02:22 PM
Post
#9
|
|
|
Member [Level 1] ![]() |