troubleshooting Question

How to print database content.

Avatar of Lennart Ericson
Lennart EricsonFlag for Sweden asked on
Web DevelopmentPHPScripting Languages
11 Comments2 Solutions462 ViewsLast Modified:
A database contains among other things the html code for pages. Some of the pages have hyperlinks. I want to print the various hyperlinks. I have tried this:

$host = 'localhost';
$usr = 'user name';
$pwd = 'password';
$db = 'dbs';
or die("<p>Kan ej ansluta till databasservern.</p>");
or die("<p>Kan ej ansluta till databasen " . $db . ".</p>");

$SQL = " SELECT * FROM jbs ";
$retid = mysql_query($SQL);

if (!$retid) { echo( mysql_error()); }

else {
        $antal = mysql_num_rows($retid);
        while ($row = mysql_fetch_array($retid)) {
            $text         = $row["text"];
            $kategori  = $row["kategori"];
            $titel         = $row["titel"];
            $sida        = $row["sida"];

$input = @file_get_contents($text) or die("Kunde inte läsa: $kategori - $titel");

$regexp = "/<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>/";
  if(preg_match_all("$regexp/siU", $input, $matches, PREG_SET_ORDER)) {
    foreach($matches as $match) {

if (!empty($regexp))       {
if (!empty($text))       {

for ($nr=0; $nr<$antal;)

echo "<tr><td>".$match[$nr][$nr+1]."</td></tr>";

It doesn't work. And I don't know where I go wrong. Is it at "$input = @file_get_contents($text)"?
Could your experts, please, help me out?
Join our community to see this answer!
Unlock 2 Answers and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros