
August 27th, 2003
02:54 AM
Help with Query Strings
Ive been playing around with PHP for a while now, basically just making my sites in the normal html way and just using php include() for it all. Ive gotten the switch() statement down, its just I want to be able to have multiple pages sorta...
Like this:
index.php?page=this&something=somethin&etc=etc
that type of thing. Its just i feel that this will help IMMENSLEY in my website coding.. i dont care if it uses switch() seing as how im currently grounded on using 1 variable..
Ive searched and searched the net, but i dont feel as if i have done enough but i just dont have the time School and all 
Can you experts help?

August 27th, 2003
03:03 AM
since you know switch, i'll use switch
<?php
$page = isset ( $_GET['page'] ) ? $_GET['page'] : 'main';
$section = isset ( $_GET['section'] ) ? $_GET['section'] : 'main';
switch ( $page )
{
default:
case 'main':
include ( 'main.php' );
break;
case 'about':
switch ( $section )
{
default:
case 'main':
include ( 'about.php' );
break;
case 'contact':
include ( 'about_contact.php' );
}
break;
}
?>
read the sticky!
___________________
http://celerondude.com

August 27th, 2003
03:23 AM
0wNe|)
___________________
Current Project: LivermoreMuscle.com
Sig Hosted by Motorspin

August 27th, 2003
10:07 PM
hey thanks CDude, I thought i might of saw it somewhere but i couldnt find it.

August 27th, 2003
11:43 PM
with Mr. Jones
Status: Offline!
http://www.tutorialforums.com/showthread.php?s=&thr ... ght=tutorial+updated might be where you saw it. Lots of comments on this subject there
___________________
http://www.philbrodeur.com - Expert PHP Development and Tutorials

August 28th, 2003
01:12 AM
Neverside Newbie
Status: Offline!
same question.. what am i doing wrong
<body>
<? php
if ( $ GET ['page' ] == 'about' ) {
include( 'about.php' );
}
if ( $ GET ['page' ] == 'projects' ) {
include( 'projects.php' );
}
?>
</body>

August 28th, 2003
01:53 AM
try:
<?php
if ( $_GET['page'] == 'about' ) {
include( 'about.php' );
} elseif ( $_GET['page'] == 'projects' ) {
include( 'projects.php' );
}
?>
___________________
ProBB - The Best Thing to Happen to BBs Since YaBB

August 28th, 2003
01:57 AM
Neverside Newbie
Status: Offline!
You were doing a lot, They're can't be any spaces between a variable, and you were close, but $GET isn't a global, $_GET is
Take it easy on the spacing a little bit. And also, use a switch statement like the one above. Read the tutorials thread. I think you'll find them quite helpful.
___________________
Travis Farrell


August 28th, 2003
02:13 AM
with Mr. Jones
Status: Offline!
why did you go from switch to if? switch is better
cdudes w/ comments, if you dont get it
<?php
$page = isset ( $_GET['page'] ) ? $_GET['page'] : 'main';
# checks if var page is set, and if it isnt assigns it main
$section = isset ( $_GET['section'] ) ? $_GET['section'] : 'main';
# checks if var section is set, and if it isnt assigns it main
switch ( $page )
{
default:
case 'main':
# site.php?page=main OR site.php
include ( 'main.php' );
break;
case 'other':
# site.php?page=other
include ( 'other.php' );
break;
case 'about':
switch ( $section )
{
default:
case 'main':
# site.php?page=about§ion=about OR site.php?page=about
include ( 'about.php' );
break;
case 'contact':
# site.php?page=about§ion=contact
include ( 'about_contact.php' );
break;
}
break;
}
?>
___________________
http://www.philbrodeur.com - Expert PHP Development and Tutorials