Home › Forums › Scripts › GirlsWhoGeek Scripts › Where does $_GET get id from
Tagged: build-a-blog, php
This topic contains 4 replies, has 4 voices, and was last updated by Vera 12 months ago.
-
AuthorPosts
-
June 20, 2012 at 2:52 pm #14056
AnonymousHello!
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
June 20, 2012 at 8:15 pm #15173The $_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.
June 20, 2012 at 11:56 pm #15174
AnonymousThank 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.
June 21, 2012 at 12:46 am #15175
AnonymousI 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).
June 21, 2012 at 4:55 am #15176langmangin: 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
-
AuthorPosts
You must be logged in to reply to this topic.




Recent Comments