Jump to content


Hyperlinks From Database ..

hyperlinks from a database

  • Please log in to reply
2 replies to this topic

#1 gabobby

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 19 November 2012 - 01:36 AM


I am new to this site and relatively new to PHP, so I would be grateful of any help.

I have the following code:

$result = mysql_query("SELECT * FROM resource");
echo "<table border='1'>

<th>Click on this link</th>
while ($row = mysql_fetch_array($result))
echo "<tr>";
echo "<td>" . $row['resource_id'] . "</td>";
echo "<td>" . $row['name_of_resource'] . "</td>";
echo "<td>" . $row['description'] . "</td>";
echo "<td>" . $row['resource_name_path'] . "</td>";
//echo "<td>".'<a href="../../8_resources/Mystical Creatures Database.mdb">'.$row['hyperlink_resource_name'].'</a>'."</td>";

echo "<td>".'<a href="'.$row['resource_name_path.'].'">'.$row['hyperlink_resource_name'].'</a>'."</td>";

echo "</tr>";
echo "</table>";

It outputs resource information from a table. However, the a href hyperlink bit doesn't work - when I click on it, it doesn't throw up an error, just takes me to an index of files page and lists the file names on the site instead of opening the above database, called 'Mystical Creatures Database.mdb.

Is there something wrong with the code?

Edited by Zane, 19 November 2012 - 02:38 AM.

#2 gabobby

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 19 November 2012 - 01:53 AM

Hi again ..

Forgot to add that the $row['resource_name_path.'] is inserting the path to the hyperlink and it is this section that I am having trouble with. The section that is // commented out actually works, but it is not pulling in the 'path' from the database.

Any ideas?

#3 trq

  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 19 November 2012 - 02:10 AM

Firstly, whats with all the concatenation? You could write this code as simply as....

echo "<td><a href=\"{$row['resource_name_path.']}\">{$row['hyperlink_resource_name']}</a></td>";

Now, what does that produce?

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users