Jump to content

Displaying links AS links...


Recommended Posts

I've created a simple link directory on my site (http://www.paulrawnsley.com/links.php) but cant figure out ho to make the 'link' entrys display as clickable links. Can anyone help?

this is the code to show the directory: [code]<?php
import_request_variables('p');
$user="XXXXXXX";
$pass="XXXXXXX";
$db="linkdb";

$link=mysql_connect("sql02",$user,$pass);
if (!$link) die ("Couldn't connect to MySQL server");
mysql_select_db($db,$link) or die("Couldn't connect to $db".mysql_error());

$query="SELECT * FROM linkdb ORDER BY `title` ASC";

$result=mysql_query($query,$link);               
print"<table align='center' width='100%' cellpadding='2' cellspacing='2' border='0'>";
print"<tr bgcolor='#b3cac5'>";
print"<font size='3'>";
print"<th>Title</th>";
print"<th>Link</th>";
print"<th>Description</th>";
print"</font>";
print"<tr>";
while ($row=mysql_fetch_row($result))
{
print"<tr>";
foreach($row as $field)
print"<td>$field</td>";
print"</tr>";
}
print"</table>";
?>[/code]
Link to comment
Share on other sites

where you're using your foreach() to loop through your row, you'll need to adjust it to allow you to pull out the column for "link" and echo it slightly differently. let's say your column name for the actual link is simply "link", you could do something like this:
[code]
<?php
while ($row = mysql_fetch_array($result)) {
  echo "<tr>\n";
  foreach ($row as $key => $val) {
    // now, let's see if it's the "link" column and show a link if it is
    if ($key == 'link') echo "<td><a href=\"$val\">$val</a></td>\n";
    else echo "<td>$val</td>\n";
  }
  echo "</tr>\n";
}
?>
[/code]

hope this helps
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.