How to make a reference in php

How to make a reference in php

Digital Hits: 58

The hyperlink is a dynamic element when clicking which the user is redirected on other page. As PHP represents language open source, there is a set of ways of the organization of links.

It is required to you

Instruction

1. Create the new sequence from PHP language commands. These commands will display the link of the browser and to redirect the user on the new page opening in a new window. The code looks approximately so:

?>

2. Put the tag of a binding HTML in the operator of printing. It is the same binding of the tag which is used in the traditional code in the HTML language. Insert the address of the necessary website and also an explanation which are necessary for you in the following order:

Click here to visit the destination page."";
?>

3. Avoid use of a backslash in quotes. The code sample in the previous step perhaps will not always work. It occurs as the quotes selecting the page address will be interpreted as the command stopping execution of the sequence. The character of a backslash is used for visualization of quotes or as a part of the tag of a binding and follows the operator of printing. The backslash is not used as functional element and is invisible to the visitor of the page:

Click here to visit the destination page."";
?>

4. Be connected to the MySQL database by means of a command:

mysql_connect (""addressOfDatabase"", ""yourUsername"", ""yourPassword"") or die (mysql_error);
mysql_select_db (""yourDatabaseName"") or die (mysql_error);

5. Create the variable for getting a link from the MySQL database, using the mysql_query PHP function. This example connects the $data variable with the mysql_query function which will conduct search by names in the database and to return all elements meeting a condition:

$data = mysql_query (""SELECT * FROM links"") or die (mysql_error ('Error, no links were found.'));

6. Find necessary references by means of the mysql_fetch_array function and make them visible for the user. In an example the new array with $info name is created. This array with information is created from variable values of $data which was created on the previous step. Then it touches data with the help of the while command. For each data element, the new cell with the name "$link" is created. Also the reference from the MySQL database for each variable is created. The $link variable is placed in the tag of a binding of HTML code, using the rule of a binding of the PHP language:

while ($info = mysql_fetch_array ($data))
{
$link= $info ['linkName'];
print "Click here to visit the destination page."";
}

Author: «MirrorInfo» Dream Team

Print