Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

67 users online



Help with Query Strings

Help with Query Strings

Currently viewing this thread: 1 (0 members and 1 guests)


Page 1 out of 4
Apothecary

Apothecary

Status: Offline!

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:

Code:


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 Sad
Can you experts help?

CDude

CDude

nothing
Status: Offline!

since you know switch, i'll use switch

PHP:

<?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

Adam

Adam

Status: Offline!

0wNe|)

___________________


Current Project: LivermoreMuscle.com
Sig Hosted by Motorspin

Apothecary

Apothecary

Status: Offline!

hey thanks CDude, I thought i might of saw it somewhere but i couldnt find it.

Phil

Phil

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

colincameron

colincameron

Neverside Newbie
Status: Offline!

same question.. what am i doing wrong

PHP:

<body>
  <? php 
     
if ( $ GET ['page' ] ==  'about' ) { 
                include( 
'about.php' ); 
        } 
     if ( $ 
GET ['page' ] ==  'projects' ) { 
                include( 
'projects.php' ); 
        } 
     
?>
</body>

killa_kid

killa_kid

Status: Offline!

try:

PHP:

<?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

Motorspin

Motorspin

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 Tongue 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
http://motorspin.com/stuff/images/avasig/m_enterprisesig.gif

colincameron

colincameron

Neverside Newbie
Status: Offline!

killa kid it didnt work

Phil

Phil

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:

<?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&section=about OR site.php?page=about
                 
include ( 'about.php' ); 
             break; 
             case 
'contact'
                
# site.php?page=about&section=contact
                 
include ( 'about_contact.php' ); 
            break;
        } 
    break; 
}

?>

___________________

http://www.philbrodeur.com - Expert PHP Development and Tutorials

Page 1 out of 4
Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0206 seconds.