Results 1 to 3 of 3

Thread: PHP, Switches, Includes...... oh the not so fun

  1. #1
    Senior Member Kezzer's Avatar
    Join Date
    Sep 2003
    Posts
    4,863
    Thanks
    12
    Thanked
    5 times in 5 posts

    PHP, Switches, Includes...... oh the not so fun

    Ok so i've been running around in circles trying to sort this problem. I've got the answer but i don't understand it. So what i wanted to do is use the article.php file to include other files which would display certain information from the database. For example http://www.kezzer.co.uk/article.php?page=photoshop

    Ok easy enough, no problems there. So how about catching the URL and getting it to display the information from the database? http://www.kezzer.co.uk/article.php?...D=2&category=3

    That wouldn't work because of the switch. So the following code was given to me to overcome this:

    PHP Code:
    This is a testfile.<br>
    <?php
    if(isset($_GET['id'])){
    echo 
    'ID: '.$_GET[.'id'].'<br>';
    }else{
    echo 
    'No ID is set.<br>';
    }
    if(isset(
    $_GET['category'])){
    echo 
    'CATEGORY: '.$_GET['category'].'<br>';
    }else{
    echo 
    'No CATEGORY is set.<br>';
    }
    ?>
    <br><br>
    I don't understand what i'm doing. My switch is so simple, it just defines the URL which is caught and tells it which file to pick up. Apparently the method given to me as the example above states is an advanced method of accomplishing what i want to do.

    Any help would be ever so nice

  2. #2
    HEXUS.social member Agent's Avatar
    Join Date
    Jul 2003
    Location
    Internet
    Posts
    19,185
    Thanks
    738
    Thanked
    1,609 times in 1,048 posts
    The code is pretty simple if you break it down. PHP usualy looks scarey when its in one big block

    This is the same as what you already have, just commented.

    PHP Code:
    This is a testfile.<br> 

    <?php
    // start the PHP
     
    if(isset($_GET['id'])){ 

    // If the variable "id" has been set via the GET method of submition (ie, its in the URL of the page) then do the following :

    echo 'ID: '.$_GET[.'id'].'<br>'

    //echo "ID :" then print the Variable value, and start a new line

    }else{ 

    // If the variable id hasnt been set, do this :


    echo 'No ID is set.<br>'

    // print "No ID is set" and start a new line

    }

    // end the IF loop

     
    if(isset($_GET['category'])){ 

    // If the variable "'category'" has been set via the GET method of submition (ie, its in the URL of the page) then do the following :

    echo 'CATEGORY: '.$_GET['category'].'<br>'

    //echo "CATEGORY :" then print the Variable value, and start a new line

    }else{ 

    // If the variable 'category' hasnt been set, do this :

    echo 'No CATEGORY is set.<br>'

    // print "No CATEGORY is set" and start a new line



    // End the IF loop.

    //End the PHP code block
    ?> 
    <br><br>
    Hopefully thats a little bit of help
    Last edited by Agent; 16-03-2004 at 06:05 PM.
    Quote Originally Posted by Saracen View Post
    And by trying to force me to like small pants, they've alienated me.

  3. #3
    Senior Member Kezzer's Avatar
    Join Date
    Sep 2003
    Posts
    4,863
    Thanks
    12
    Thanked
    5 times in 5 posts
    Indeed that does

    So i still use my switch, but to display the data i use that code?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. PHP and MySQL
    By Kezzer in forum Software
    Replies: 4
    Last Post: 28-10-2003, 02:59 PM

Posting Permissions

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