PDA

View Full Version : PHP Page Combining




ZicklePop
May 20, 2005, 08:51 PM
I'm new to php and I would like to figure out how to do the thing where websites send you to something like visit test.php?string=variable1 to see one webpage and test.php?string=variable2 to see another webpage. How would I do this any is there any tutorials or something? Thank you.



neoserver
May 20, 2005, 09:29 PM
i would use something like a switch statement.. look it up in the PHP documentation if you need help.

<?php
$area = $_GET['area'];

switch($area){
case "1":
include("pageone.php");
break;
case "2":
include("pagetwo.php");
break;
default:
echo "Invalid area code";
} // switch
?>
Of course you can change the numbers to strings and replace the filenames. I hope you get the idea.. the PHP documentation is a great place to look :)

ZicklePop
May 20, 2005, 09:57 PM
i would use something like a switch statement.. look it up in the PHP documentation if you need help.

Of course you can change the numbers to strings and replace the filenames. I hope you get the idea.. the PHP documentation is a great place to look :)
Thanks alot, is there any way to do it in the same file though? 'Cause currently I do something like that.

And I'ma going to go look at it(PHP Documentation) heh..

neoserver
May 20, 2005, 10:01 PM
so you want the entire webpage in one file? thats not a problem :)

just replace the switch statement with this one

switch($area){
case "1":
?>
HERE IS THE HTML FOR THAT PAGE
<?php
break;
case "2":
?>
AGAIN HTML FOR THE PAGE
<?php
break;
default:
echo "Invalid area code";
} // switch

or if you had actual PHP code to produce your pages you could just replace the include functions with the actual PHP code to generate your pages :)Hope i have helped.

ZicklePop
May 20, 2005, 10:13 PM
so you want the entire webpage in one file? thats not a problem :)

just replace the switch statement with this one

or if you had actual PHP code to produce your pages you could just replace the include functions with the actual PHP code to generate your pages :)Hope i have helped.
Ah, thank you!

neoserver
May 20, 2005, 10:14 PM
No Problem :) Glad i could help you.

ZicklePop
May 21, 2005, 08:14 PM
Okay I have another question, is this something I would want to do to a whole website (AKA: www.zicklepop.com )?

neoserver
May 21, 2005, 08:29 PM
what i would do is make the index.php generate all the common stuff like the logo etc. Then i would use the code i have given you already and place it into that page.. now, then i would move the content and put it in different .php files and include them using the first sample. Thats how i would do it but you could do it the second way i showed you and put everything in one file, that is certainly the easiest.

superbovine
May 21, 2005, 10:13 PM
generally, i split pages in the 3 areas, headers, body, and footer then you can have dynamic universal headers and footers for everypage and a dynamic body as well.

ZicklePop
May 21, 2005, 11:50 PM
Yeah that's what I currently do.

Thanks alot :)