Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18
  1. #1
    Junior Member
    Join Date
    Dec 2003
    Posts
    23
    Member #
    4154
    I'm currently building a website w/ PHP, and i saw @ a couple of websites its like www.domain.com/index.php?id=x
    I know what it is.. But i don't know the name.. So i can't find a tut on it. Can any1 tell me the name and/or a good tutorial for it? Or even better, explain it himself?
    Thnx in advance

  2.  

  3. #2
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    137 times
    ID is a variable on the page. Depending on the value of ID, certain info will load.
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  4. #3
    ASP
    ASP is offline
    Junior Member
    Join Date
    Aug 2003
    Posts
    6
    Member #
    2786
    It's a GET variable.

    This one is accessable through $_GET['id'] or $HTTP_GET_VARS['id'], depending on your server config.

    What kind of information did you want on it?

  5. #4
    Junior Member
    Join Date
    Dec 2003
    Posts
    23
    Member #
    4154
    Originally posted by Wired
    ID is a variable on the page. Depending on the value of ID, certain info will load.
    Yeh thats it..
    A standard layout that will load a different content..
    Tuorials any1?

  6. #5
    Senior Member
    Join Date
    Aug 2003
    Posts
    444
    Member #
    2801
    Actually it is called a QUERY_STRING, and it is an evironment variable that the server sets to be equal to everything after the question mark.

    The query string is also the mechanism of implementing the HTTP GET method. The other famous one is POST. You must have used either/both when composing forms. There is a lesser-known one called HEAD.

    What PHP does is turn the query string into an array of variables stored in $_GET[].

    So for more info, just search for info about working with query strings.
    eKstreme
    eKstreme.com - Free website tools!
    fontfox - free fonts Hand-picked quality fonts.

  7. #6
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    Say you had your content stored in a table in your database, it would be something like this:
    PHP Code:
    $id $_GET['id'];
    $sql "SELECT * FROM `tablename` WHERE `id`='$id'";
    $query mysql_query($sql);
    $row mysql_fetch_array($query); 
    Then you would use the output on your page. Say you had two fields in your table, called 'title' and 'text' then you could do something like this...

    PHP Code:
    <?php
    $id 
    $_GET['id'];
    $sql "SELECT * FROM `tablename` WHERE `id`='$id'";
    $query mysql_query($sql);
    $row mysql_fetch_array($query);
    $title $row['title']
    $text $row['text']
    ?>
    <html>
    <head>
    <title>Viewing Page - <?php echo $title ?></title>
    </head>
    <body>
    <h1><?php echo $title ?></h1><br /><br />
    <?php echo $text ?>
    </body>
    </html>
    A very simple example, but do you get the idea?
    JR

  8. #7
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    ASP and eKstreme,

    Thanks for the mind-blowing definitions, but PyroManiac was asking for a simple example, not a definition spewed from a dictionary. JR, thanks for giving an example (and setting an example, I might add).

    If I may, I'd like to simplify it a bit, though. He may not have database access.
    PHP Code:
    <html>
        <head>
            <title>My Page</title>
        </head>
        <body>
        <?php
        
    switch ($_GET['id']) {
            case 
    1:
        
    ?>
            <h1>Page 1</h1>
            <p>Page 1 Content</p>
        <?
                
    break;

            case 
    2:
        
    ?>
            <h1>Page 2</h1>
            <p>Page 2 Content</p>
        <?
                
    break;

            default:
        
    ?>
            <h1>Default Page</h1>
            <p>Default Page Content</p>
        <?
                
    break;
        }
        
    ?>
        </body>
    </html>

  9. #8
    Junior Member
    Join Date
    Dec 2003
    Posts
    23
    Member #
    4154
    Thanks all of u..
    @Transio:
    So that would be my index page? and if I type index.php?id=1
    U'll get Page 1 w/ content? Sounds good.. And btw, i do have access
    @JR:
    Sounds good too, but I do want 2 keep it simple..
    But thnx a lot 2..

  10. #9
    Junior Member
    Join Date
    Dec 2003
    Posts
    23
    Member #
    4154
    btw.. I have a page, that sometimes isnt there, but most of the time it is.. Can i make some code, that it displays the page if it is there (in the code i got from transio, w/ include..) it displays it, but if it isn't it says something like "No page here today" in the content..?
    thnx in advance..

  11. #10
    Senior Member
    Join Date
    Aug 2003
    Posts
    444
    Member #
    2801
    Originally posted by PyroManiac^
    btw.. I have a page, that sometimes isnt there, but most of the time it is.. Can i make some code, that it displays the page if it is there (in the code i got from transio, w/ include..) it displays it, but if it isn't it says something like "No page here today" in the content..?
    thnx in advance..
    Yes there is. The way to do it is to check if the file is there or not. PHP gives you the file_exists() function. The code would be:

    if(file_exists($file)){
    require $file;
    }
    else{
    echo "<p>No page here today.</p>";
    }
    eKstreme
    eKstreme.com - Free website tools!
    fontfox - free fonts Hand-picked quality fonts.


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:47 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com