Where does $_GET get id from

Home Forums Scripts GirlsWhoGeek Scripts Where does $_GET get id from

Tagged: ,

This topic contains 4 replies, has 4 voices, and was last updated by  Vera 12 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #14056

    Anonymous

    Hello!

    I have been working on figuring this out for 2 days now and have decided it’s time to just ask the question!

    My confusion is about this code block from Part 3: Display Entries:

    if (!isset($_GET) || !is_numeric($_GET)) {

    die(“Invalid ID specified.”);

    }

    $id = (int)$_GET;

    $sql = “SELECT * FROM php_blog WHERE id=’$id’ LIMIT 1″;

    Where does $_GET get the value of id from? It appears to be the id of the entry in the database (primary key, auto increment) but I don’t see it retrieved or handled in any way from the query result.

    Thank you for your help!

    La Vonne

    #15173

    Amelie
    Keymaster

    The $_GET array is populated from the query string, i.e. what is entered after the ? in the URL, e.g. page.php?id=123. $_GET in this case refers to the ‘id’ part in that URL, so it would be 123.

    #15174

    Anonymous

    Thank you for responding Amelie, but all apologies, I am still not clear.

    How did the id get into the url in the first place? I do understand what the $_GET array is, etc….but in the context of the blog tutorial, section 3, I do not see how the id is given a value nor put into the url.

    If you have the time/inclination to clarify I would really appreciate it.

    #15175

    Anonymous

    I am not sure exactly what you don’t understand. The id is put in the URL by you typing it into the browser. The $_GET superglobal pulls info out of the URL. As Amelie explained, if the URL is

    journal.php?id=1

    You would use $_GET to get the ID of an entry. In this case one. We could use something other than “id”. For example, you could use orange

    journal.php?orange=1

    Then you would use $_GET to get the id you are typing into the URL (in this case 1).

    ID is given a value here

    $id = (int)$_GET['id'];

    ID is populated with whatever ID you put in the URL. (e.g. journal.php?id=127, id would be 127).

    #15176

    Vera
    Participant

    langmangin: The tutorial uses a sort of “convention” that all individual blog entry pages’s URLs should look like http://myurl.com/id=id_of_blog_in_database (where id_of_blog_in_database is a number).

    You’d normally get to an individual blog page, from an archives page. This page, normally contains a list of links to all blog entries, where all links look something like the example above. You can read more about creating an archive in Part 5 of the BAB tuorial: http://girlswhogeek.com/tutorials/2004/part-5-building-an-archives-page

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.