View Full Version : Page ID's - $_GET

06-29-2007, 07:04 AM

I'm trying to figure out how to make a page URL like www.example.com/index.php?page=username

With some help of another guy, I've come up with this.

$nick = "test";

$query = "SELECT * FROM members WHERE user_name = '$nick'";
$result = mysql_query($query,$db);

$row = mysql_fetch_array($result);

$userid = $row['user_id'];

Then he showed me for the link, I'd use something like this:

echo "<a href=\"index.php?page=$userid\">Asdissimo</a>";

Now the part that really confuses me is that when I press the link, he told me this comes into play

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

your code here

I have no idea where the $_GET['page' comes from, or how to use it.

Can someone possibly help?

06-29-2007, 07:28 AM
That Stuff after the "?" in the URL is called a query string. Google "query string" +tutorial +php

06-29-2007, 08:52 AM

$_GET is An associative array of variables passed to the current script via the HTTP GET method.

if you want to know.....
copy and paste this code to "index.php" file and save it

echo "<a href=\"index.php?page=Asdissimo\">Asdissimo</a> <br>";
echo "<a href=\"index.php?page=Angel\">Angel</a> <br>";
echo "<a href=\"index.php?page=fl00d\">fl00d</a> <br>";

if(isset($_GET['page'])) {
echo "Hello , ";
echo $_GET['page'];

if you click first link ... the result will be "Hello , Asdissimo"
if you click second link ... the result will be "Hello , Angel"
.. and so on.....:thumbsup:

you can test with more variable... to see the different.

echo "<a href=\"index.php?page=Asdissimo&age=17\">Asdissimo</a> <br>";
echo "<a href=\"index.php?page=Angel&age=14\">Angel</a> <br>";
echo "<a href=\"index.php?page=there&age=70\">there</a> <br>";

if(isset($_GET['page'])) {
echo "Hello , ";
echo $_GET['page'];
echo "<br> You are ";
echo $_GET['age'];
echo " years old.";

hope this usefull :thumbsup:

06-30-2007, 04:51 AM
ok yes i see now. thanks. what I was getting confused about wsa the ['page'] part of the $_GET associative array. i couldnt figure out where it was getting defined but now i see. thanks ;)