displaying words from db as links in php
i have words like 123.com , 23开发者_C百科4.org in database how to display them as links?
<?php
$con=mysql_connect("localhost","root","123");
mysql_select_db("www",$con);
$result=mysql_query("SELECT * FROM Tag");
for ($c=0; $c< mysql_num_rows($result); $c++)
{
$f=mysql_fetch_array($result);
###########echo $f['name']." ";
}
mysql_close($con);
?>
You need to output the HTML for a link. Something along the lines of:
print "<a href=\"" . $url . "\">" . $f['name'] . "</a>";
replacing url with the site URL you want the link to go to. It sounds like it might also be $f['name'].
echo '<a href="'.$f['name'].'">'.$f['name'].'</a>';
This should work:
$result=mysql_query("SELECT * FROM Tag");
while($f=mysql_fetch_array($result)){
echo "<a href='" . $f['name'] . "'>" . $f['name'] . "</a>";
}
mysql_close($con);
?>
A link in html code looks like this:
<a href="123.com">123</a>
The php you are using only outputs this to html:
123.com
links are html.
echo '<a href="'.$f['name']'.">Click me</a>';
精彩评论