SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    UK
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    index.php?page=something&somethingelse=newpage help

    yes well i no how to get index.php?page=newpage

    but im strugling to get index.php?page=something&somethingelse=newpage

    here is teh code im tryin to use since i though it would work
    incase you cant tell im new to this php stuff lol

    $page = $_GET['index.php?page=tuts&photshop='];

    switch($page){
    case '':
    //This is the default page to be loaded as your index
    default:
    require('index.php?page=tuts');
    break;
    //Your Pages
    case 'vector':
    require('vector.php');
    break;
    }


    so how stupid can i be lool, i would love your help and it would mean alot to me, thanks in avance to who ever helps me

  2. #2
    SitePoint Evangelist webchalkboard's Avatar
    Join Date
    Jan 2005
    Location
    Bristol, UK
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    umm maybe i'm missing the point here, but that really doesn't make a lot of sense to me.

    Are you trying to include a different file depending on which page is set in the page variable in the URL?

    Well why don't you just do something like this:

    if ($_GET['page']=='tut') {
    include 'tut.php';
    } elseif ($_GET['page']=='vector') {
    include 'vector.php';
    }

    sorry I don't really get what you are trying to do, hope thats some help.
    Websites for Sale - Sell websites in a purpose built marketplace
    Then do some Shopping

  3. #3
    SitePoint Wizard
    Join Date
    Jul 2004
    Location
    Minneapolis, MN
    Posts
    1,924
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It does seem odd how your getting the get variables, you should get each one seperate for what you're trying to do. I think that webchalkboard's code would work fine.

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    UK
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but how would i get it to show up as the title of this thread, i no how to get the index.php?page=tut but no the &photoshop=vector bit on the end. wouldnt the code web give me just show index.php?page=vector. god i hate learning

  5. #5
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ltjfansite
    $page = $_GET['index.php?page=tuts&photshop='];
    This isn't how to use $_GET.

    With this URL: index.php?page=something&somethingelse=newpage

    Then, $_GET['page'] == 'something' and $_GET['somethingelse'] == 'newpage'.

    Douglas
    Hello World

  6. #6
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ltjfansite
    switch($page){
    case '':
    //This is the default page to be loaded as your index
    default:
    require('index.php?page=tuts');
    break;
    //Your Pages
    case 'vector':
    require('vector.php');
    break;
    }
    Default should be last:

    PHP Code:
    switch($_GET['page']){
      case 
    'vector':
        require(
    'vector.php');
        break;
      default:
        require(
    'index.php?page=tuts');

    It also means that you don't need the "case ''" bit.

    See: http://www.php.net/switch

    A special case is the default case. This case matches anything that wasn't matched by the other cases, and should be the last case statement.

    Douglas
    Last edited by DougBTX; Feb 21, 2005 at 13:29.
    Hello World

  7. #7
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    UK
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i think i get it. thanks ill try it. would this work?

    switch($_GET['page']){
    case 'vector':
    require('vector.php');
    break;
    default:
    require('index.php?page=tuts');
    break;
    }
    switch($_GET['page']){
    case 'aboutus':
    require(aboutus.php');
    break;
    default:
    require('index.php');
    break;
    }

    so its all in one script if you get me.
    Last edited by ltjfansite; Feb 21, 2005 at 09:29. Reason: forgot to add something

  8. #8
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    San Diego, CA (USA)
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    switch ($_GET['page']) {
         case 
    'vector':
              require(
    'vector.php');
              break;

         case 
    'aboutus':
              require(
    'aboutus.php');
              break;

         case 
    'anotherpage':
              require(
    'anotherfile.php');
              break;

         default:
              
    //Default is what the script goes to if the variable doesnt match any other cases. It does not require a "break;"
              
    require('index.php?p=tuts');


  9. #9
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could also do it like this. Less code to change if you need to add more pages:

    PHP Code:
    // An array of valid pages
    $pages = array(
        
    'vector'      => 'vector.php',
        
    'aboutus'     => 'aboutus.php',
        
    'anotherpage' => 'anotherfile.php',
        
    'default'     => 'index.php?p=tuts'
    )

    // See if we've been asked for a page,
    // If so, see if it is a valid page
    $valid_page = isset($_GET['page'])
               && isset(
    $pages[$_GET['page']]);

    // If it is a valid page, use that, otherwise use 'default'.
    $page_name $valid_page $_GET['page'] : 'default';

    // Require the page using it's name and the array up top.
    require $pages[$page_name]; 
    Edit: just removing some more duplication, adding comments.

    Douglas
    Last edited by DougBTX; Feb 21, 2005 at 15:29.
    Hello World

  10. #10
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    UK
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok thanks but i still dont ge how i can make my code have links going like

    index.php?page=aboutus

    and

    index.php?page=tuts&photoshop=vector

    sorry to be a pain.

  11. #11
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ltjfansite
    ok thanks but i still dont ge how i can make my code have links going like
    Well... what do you want that URL to do?

    If you want to have it bring up a page with the words "I want to do a photoshop tutorial on vectors!" then it could be:

    PHP Code:
    if ($_GET['page'] = 'tuts' && $_GET['photoshop'] = 'vector') {
      echo 
    'I want to do a photoshop tutorial on ' $_GET['photoshop'] . 's!';

    It does seem like a rather odd URL though, wouldn't you want it more like this:

    index.php?page=tutorial&application=photoshop&tool=vectors

    Then you could have this:

    PHP Code:
    echo 'I want to do a ' $_GET['application'] . ' ' $_GET['page'] . ' using ' $_GET['tool'] .'!'
    hth,
    Douglas
    Hello World

  12. #12
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    UK
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    something like this

    index.php?page=tuts&cat=photoshop&id=vector

    that would be a better url id say,

    so the index.php?page=tuts will take you to the main tutorial section which lists all the programs that has tutorials for.

    then the index.php?page=tuts&cat=photoshop will take you to the photodshop tut page then you click the link to the vector tut which will be index.php?page=tuts&cat=photoshop&id=vector

    i wont something like that

  13. #13
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    UK
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DougBTX
    This isn't how to use $_GET.

    With this URL: index.php?page=something&somethingelse=newpage

    Then, $_GET['page'] == 'something' and $_GET['somethingelse'] == 'newpage'.

    Douglas

    ok ive jsut notcied this, i think this is what im lookign for. i didnt see this at first

  14. #14
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ltjfansite
    something like this

    index.php?page=tuts&cat=photoshop&id=vector

    that would be a better url id say
    All the examples are quite bad. A better URL would be:

    http://www.example.com/tuts/photoshop/vector

    Now that you know how to use $_GET, it's probably time to start learning how to use clean URLs

    Douglas
    Hello World


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •