Results 1 to 9 of 9

Thread: PHP ID tags???

  1. #1
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default PHP ID tags???

    Ok, I keep seeing these and I want to know how to make these...
    Like on some sites where they have multiple products they have a link and in the bottom it says:
    Code:
    http://www.site.com/items?id=38324
    How do I get it so I can do something like that???

    Sorry to be so vague but I really don't know how to do this or what exactly it is but its cool...

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    All that the id part of the url you listed above is just a simple GET variable. In other words, you would do something like this to get the value of what is submitted in the url:

    Code:
    <?php
     $id = $_GET['id']; //will assign the value of 38324 for the url listed above.
    
    /* After getting the above variable, you can use that to identify the id of a certain database entry, or a file, or whatnot. */
    ?>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    k... I thought it was something like that... Let me get this straight...

    would it be something like this:
    Code:
    <?php
    $id = $_GET['id'];
    if($id==2){
    include("file1.php");
    }else{
    include("index.php");
    }
    ?>
    I don't think its that...

    but if i wanted to do it via database how would I go about doing that?

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Quote Originally Posted by Rockonmetal View Post
    would it be something like this:
    Code:
    <?php
    $id = $_GET['id'];
    if($id==2){
    include("file1.php");
    }else{
    include("index.php");
    }
    ?>
    You could do it that way, because "id" could be anything else; such as: text, testing, ids, something, blah, etc. Being that it is just a variable, the possibilities are endless.

    if i wanted to do it via database how would I go about doing that?
    Step 1: Set up your database to your liking and to suit your need.
    Step 2: Set up the php script to connect to the database.
    Step 3: Use the unique identifier as a way to get the data you want to extract.
    Step 4: Set up the script to pull up those entries.

    So this would be something like the following for example:

    list.php
    Code:
    <?php
     include('dbconnect.php'); //all of your database connection stuff
    
    if (isset($_GET['id'])) {
      $getItem = mysql_query("SELECT * FROM `table` WHERE `id`='" . $_GET['id'] . "'");
     
        while ($q = mysql_fetch_array($getItem)) {
          echo $q['somecolumn']; //this will echo the column value that you specify
        }
    }
    
    else { //if the id is not set, show all items in database
     $the_list = mysql_query("SELECT * FROM `table`");
     
     while ($q = mysql_fetch_array($the_list)) {
    ?>
    <a href="?id=<?php echo $q['id'];?>">Click here for the item</a> | <?php echo $q['somecolumn'];?> <BR>
    <?php
     }
    }
    ?>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    K thanks man... I'll try that as soon as I get mysql working...

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    http://php-mysql-tutorial.com
    go through that and a lot of your database questions should be cleared up.
    mysql is not very hard, but it's not similar to other languages, so you'll need to get some experience before it starts making sense.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    If you're just starting with databases, there are other (better) solutions available like PostgreSQL.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Quote Originally Posted by Twey View Post
    If you're just starting with databases, there are other (better) solutions available like PostgreSQL.
    How is it better than MySQL(i)?
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It adheres to the SQL standard a lot better, as well as having arguably better performance.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •