Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get value from URL [closed]

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;    
}
like image 441
Vaja Axobadze Avatar asked Sep 22 '13 13:09

Vaja Axobadze


People also ask

How do I get the value of a URL?

For getting the URL parameters, there are 2 ways: By using the URLSearchParams Object. By using Separating and accessing each parameter pair.

Which method will pass the value via URL?

Submitting form values through GET method A web form when the method is set to GET method, it submits the values through URL.

What is URLSearchParams?

The URLSearchParams interface defines utility methods to work with the query string of a URL.

What is URL value?

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 (&).


1 Answers

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
}
like image 103
Steven Avatar answered Oct 21 '22 04:10

Steven