Jump to content

link to file if exists, no link if no file


mrsrowe

Recommended Posts

Hello

 

I am sure this is on the board somewhere, but I cannot find it.  I had a db with a list of documents, some of these documents have files which can be downloaded.  I have put the a link to the file name in the db, now I want to be able to create an icon which links to the file if it exists and shows nothing if there is no file.

 

My query returns the title, abstract and some other stuff about the document. 

 

$query = "SELECT DocID, DocTitle, Abstract, DocLink, fileType FROM tblDoc ORDER BY PubYear DESC";

 

the table I echo it all out into is made like this:

 

echo '<tr  valign="top" bgcolor="' . $bg . '">';

echo '<td align="left">' . $row['DocTitle'] . '</td>';

echo '<td align="left">' . $row['Abstract'] . '</td>';

echo '<td align="left">' . $row['PubYear'] . '</td>';

 

I want to be able to do somthing like this:

 

echo '<td align="left"><a href="eftec_reports/' . $row['DocLink'] . '"><img src="' . $row['fileType'] . '"></a></td>';

 

but of course it doesn't work.

 

I am never sure how to refer to the things I want to use from the db.  I think I need an if statement something like

 

if DocLink is not null,

then create an <a href.... and use an image to make the link active

 

hope this makes sense.

 

any help appreciated.

 

 

Looks like you need something like this while looping through the db records

 

$file = "eftec_reports/" . $row['DocLink'];
if(is_file($file)) {
  echo   "<td align=\"left\"><a href=\"eftec_reports/" . $row['DocLink'] . "\"><img src=\"" . $row['fileType'] . "\"></td>";
}

 

good luck...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.