Create a Link From a Database With PHP

Learn a simple process to echo HTML with a URL to a database link

Often people new to working with databases are able to fetch the information they need and echo it onto a page, but then they struggle with figuring out how to link the results for use on a website. This is a simple process in which you echo the appropriate HTML and call the URL in the middle of it. You can use PHP to connect to and manipulate databases. The most popular database system used with PHP is MySQL.

Together, PHP and MySQL are cross-platform.

Create a Link From a MySQL Database With PHP

In this example, you fetch an array and assign it to $info, and one of the fields holds email addresses.

 while($info = mysql_fetch_array( $data )) 
 Print $info['name'] . "
 Print "

Note that this code called .$info['email'] twice—once to display the email and once to be used in the link. The actual href linking code is placed around the information using print or echo and separated with dots.

Here is another example using a web address and website name.

 while($info = mysql_fetch_array( $data )) 
 Print "" .$info['sitetitle'] . "

Again you first print the

The URL generated with this code can be used on your website to provide a link to the information contained in the MySQL database.

mla apa chicago
Your Citation
Bradley, Angela. "Create a Link From a Database With PHP." ThoughtCo, Aug. 21, 2017, Bradley, Angela. (2017, August 21). Create a Link From a Database With PHP. Retrieved from Bradley, Angela. "Create a Link From a Database With PHP." ThoughtCo. (accessed March 22, 2018).