I want to get the value from the URL to choose data from the database by ID. I want the value for the id.
For example, if I were to open `www.example.com/index.php?id=12′. I want to get a value whose id = 12 in the database.
If I open `www.example.com/index.php?id=7′.
I want to get the value whose id = 7 in the database and so on.
I have some code:
JavaScript
x
$results = mysql_query("SELECT * FROM next WHERE id=$id");
while ($row = mysql_fetch_array($results))
{
$url = $row['url'];
echo $url;
}
Advertisement
Answer
Website URL:
JavaScript
http://www.example.com/?id=2
Code:
JavaScript
$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
}