mrsrowe Posted March 11, 2008 Share Posted March 11, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/95699-link-to-file-if-exists-no-link-if-no-file/ Share on other sites More sharing options...
matto Posted March 11, 2008 Share Posted March 11, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/95699-link-to-file-if-exists-no-link-if-no-file/#findComment-489996 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.