Jump to content


Displaying links AS links...

  • Please log in to reply
2 replies to this topic

#1 Rawns

  • Members
  • PipPip
  • Member
  • 10 posts
  • LocationUK

Posted 07 September 2006 - 04:51 PM

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:
	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";
	print"<table align='center' width='100%' cellpadding='2' cellspacing='2' border='0'>";
	print"<tr bgcolor='#b3cac5'>";
	print"<font size='3'>";
	while ($row=mysql_fetch_row($result))
		foreach($row as $field)

#2 obsidian

  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 07 September 2006 - 05:00 PM

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:
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";

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 Rawns

  • Members
  • PipPip
  • Member
  • 10 posts
  • LocationUK

Posted 07 September 2006 - 05:19 PM

Its kind-of helped. The text does link but its messed the table up big time...

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users