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.

 

 

Link to comment
Share on other sites

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

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.