job.answiz.com
2 Answers
  • 0
Votes
name
name Punditsdkoslkdosdkoskdo

How get value from URL in  php

I want to get value from URL to choose data from database by ID. I want value for id.

For example if I open www.example.com/index.php?id=12
I want to get value whose id = 12 in database.

If I open www.example.com/index.php?id=7
get value whose id = 7 in database and so on.

I have some code :

$results = mysql_query("SELECT * FROM next WHERE id=$id");    
while ($row = mysql_fetch_array($results))     
{       
    $url = $row['url'];
    echo $url;    
}

Website URL:

http://www.example.com/?id=2

Code:

$id = intval($_GET['id']);
$results = mysql_query("SELECT * FROM next WHERE id=$id");    
while ($row = mysql_fetch_array($results))     
{       
    $url = $row['url'];
    echo $url; //Outputs: 2
}
  • 1
Reply Report