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:
$results = mysql_query("SELECT * FROM next WHERE id=$id");
while ($row = mysql_fetch_array($results))
{
$url = $row['url'];
echo $url;
}
For getting the URL parameters, there are 2 ways: By using the URLSearchParams Object. By using Separating and accessing each parameter pair.
Submitting form values through GET method A web form when the method is set to GET method, it submits the values through URL.
The URLSearchParams interface defines utility methods to work with the query string of a URL.
URL parameter is a way to pass information about a click through its URL. You can insert URL parameters into your URLs so that your URLs track information about a click. URL parameters are made of a key and a value separated by an equals sign (=) and joined by an ampersand (&).
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With