GFXVoid Graphic Design Forum

Remove Text Formatting
Loading...

» Online Users: 3,921

0 members and 3,921 guests
No Members online

» Site Navigation

 > FAQ

» Stats

Members: 35,442
Threads: 103,075
Posts: 826,688
Top Poster: cc.RadillacVIII (7,429)
Welcome to our newest member, Lekelindids
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2005
    Location
    Floorboards
    Posts
    823

    Default

    Ok, so, many of you have seen things like index.php?id=1 or index.php?id=1&type=blah on websites. Here is how we designers do it.

    For something with one variable, like index.php?id=1, use the following code. Place this code as your entire index.php (NOTE - It HAS to be index.php, .html will do you no good).

    Code:
    <?php
    
    $page_id = $_GET['id'];
    
    switch($page_id) {
     *case '1': //page 1
     * *require_once('001.php');
     * *break;
     *case '2': //page 2
     * *require_once('002.php');
     * *break;
     *default: //if no cases matched
     *	require_once('index2.php');
     * *break;
    	}
    	
    ?>
    Please note you must make 001.php and 002.php and index2.php for that to not give you any errors.

    For multiple variables (I am only using two, but you can add more) like index.php?id=1&type=blah, use this code in your index.php.

    Code:
    <?php
    
    $page_id = $_GET['id'];
    $type_id = $_GET['type'];
    
    if(empty($_GET['id'])&&empty($_GET['type'])){
    require_once('index2.php'); //index page
    }elseif(empty($_GET['id'])&&$type_id=='blah'){
    require_once('index2.php');
    }elseif ($page_id=='1' && $type_id=='blah'){
    require_once('index_blah.php');
    }elseif ($page_id=='1' && $type_id=='noblah'){
    require_once('index_noblah.php');
    }else {
    require_once('index2.php'); //if no cases matched
    } 
    
    ?>
    You can put as many elseifs in there as you like. I hope this helps some of you.

  2. #2
    Join Date
    Mar 2005
    Location
    Insanity Sq.
    Posts
    3,811

    Default

    Yea, i know this. Isn't it better to use the $POST[] to pass variables to page from page though?
    If you want help...
    Screw you
    If you make sigs...
    Screw you

  3. #3
    Join Date
    Feb 2005
    Location
    Floorboards
    Posts
    823

    Default

    It is, but this isnt passing variables. My code is all you should have in index.php. It then $_GETs other pages, not other variables. All the variables are on that one page, so there is no need for $_POST. If you were making a login script that used multiple pages or something like it, then you need $_POST.

  4. #4
    Join Date
    Mar 2005
    Location
    Insanity Sq.
    Posts
    3,811

    Default

    I mean passing the variables for each page. For example, the way you would do that is by makinga link to http://page.com?id=1 and that would pass the variable, but it would make the URLs cleaner if you just used a POST statement then to decide the include you would get the post.
    If you want help...
    Screw you
    If you make sigs...
    Screw you

  5. #5
    Join Date
    Feb 2005
    Location
    Floorboards
    Posts
    823

    Default

    Really, $_GET works fine. I dunno what else you would have to change if you switched it to $_POST. My script really does the job in a clean manner, but you are welcome to use $_POST.

  6. #6
    Join Date
    Feb 2005
    Location
    Floorboards
    Posts
    823

    Default

    Sorry for the double post.

    Actually, you cannot use $_POST because that sends variables. You are getting variables. index.php?id=1. You are GETTING the id, not posting it. So you have to use $_GET in this case.

Similar Threads

  1. Fresh and new
    By Phazel in forum Introductions
    Replies: 5
    Last Post: 01-26-2006, 09:11 AM
  2. Fresh out the oven....
    By Mr Toasty in forum Sigs & Manips
    Replies: 4
    Last Post: 09-20-2005, 09:41 AM
  3. A fresh...
    By Spikee in forum Sigs & Manips
    Replies: 11
    Last Post: 08-03-2005, 06:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Powered by vBadvanced CMPS v4.1.1