user1687163
user1687163

Reputation:

php variable into a html hyperlink

I have looked at all the posts I could find but they don't quite to seem to do it!

Any help appreciated.

Have inserted relevant php code here:

Previously having done the search and placed the number of matches in the variable $num_rows I then turn the relevant data into variables $displayurl and $displaytitle, then place them in a table cell. I want to display the data in $displayurl as a hyperlink.

$i = 0;

while ($i < $num_rows) {
$displayurl=mysql_result($result,$i,"url");
$displaytitle = mysql_result($result, $i, "pagetitle");
echo "<tr>";    
echo "<td align = left>"  .$displayurl. " </td>"; 
echo "<td align = left> " .$displaytitle. " </td>";
echo "</tr>";

$i++;
}

Upvotes: 0

Views: 2241

Answers (4)

rrehbein
rrehbein

Reputation: 4170

In the HTML, an anchor tag or link is written as <a href="url goes here">Text that gets the underline</a>

<?php

$i = 0;

while ($i < $num_rows) {
    $displayurl   = mysql_result($result, $i, 'url');
    $displaytitle = mysql_result($result, $i, 'pagetitle');
    echo '<tr>';
    echo '<td align="left"> <a href="' . $displayurl . '">'  . $displayurl . '</a> </td>';
    echo '<td align="left"> ' . $displaytitle . ' </td>';
    echo '</tr>';

    $i++;
}

Upvotes: 0

codingbiz
codingbiz

Reputation: 26396

You can also do it this way

echo "<td align = left><a href='$displayurl'>Click here</a></td>"; 

OR

echo "<td align = left><a href=\"$displayurl\">Click here</a></td>"; 

Upvotes: 0

Teena Thomas
Teena Thomas

Reputation: 5239

echo "<td align = left><a href='" .$displayurl. "'>link1</a></td>";

Upvotes: 1

Majid Laissi
Majid Laissi

Reputation: 19798

surround it by <A> tag

$i = 0;

while ($i < $num_rows) {
$displayurl=mysql_result($result,$i,"url");
$displaytitle = mysql_result($result, $i, "pagetitle");
echo "<tr>";    
echo "<td align = left><a href='"  .$displayurl. "'>link1</a> </td>"; 
echo "<td align = left> " .$displaytitle. " </td>";
echo "</tr>";

$i++;
}

Upvotes: 0

Related Questions