carterlangley Posted April 4, 2012 Share Posted April 4, 2012 Hi guys, I have a file location stored in mysql. when i populate the table i need this file location to be a hyperlink to the file itself, so the visitors can click like a normal link and open the file in word and pdf (both formats stored). example of file location as in db "_private/Incident_Reports/Incident%20-%20Applecross%20-%2017%20December%202010%20-%20Website.doc" example of php code echo $row['word_document']; any ideas would be really appreciated. Link to comment https://forums.phpfreaks.com/topic/260365-file-location-stored-in-database-retrieval-to-html/ Share on other sites More sharing options...
trq Posted April 4, 2012 Share Posted April 4, 2012 Any ideas? You haven't told us the problem. Link to comment https://forums.phpfreaks.com/topic/260365-file-location-stored-in-database-retrieval-to-html/#findComment-1334483 Share on other sites More sharing options...
samshel Posted April 4, 2012 Share Posted April 4, 2012 please post some code Link to comment https://forums.phpfreaks.com/topic/260365-file-location-stored-in-database-retrieval-to-html/#findComment-1334484 Share on other sites More sharing options...
carterlangley Posted April 5, 2012 Author Share Posted April 5, 2012 OK, here is the code I have. It is populating the table but I need the last two colums to be hyperlinks to a file and not just the file location. If you go to the site, http://www.highland4x4response.co.uk/incident_log.php you will see what it currently looks like. Here is the code. $quey1="select * from incident_log"; $result=mysql_query($quey1) or die(mysql_error()); echo "<div align=\"center\">"; echo "<table class=\"hovertable\" width=\"100%\">"; echo "<tr>"; echo "<th>event type</th>"; echo "<th>call out by</th>"; echo "<th>call out date</th>"; echo "<th>responders</th>"; echo "<th>location</th>"; echo "<th>report in word</th>"; echo "<th>report in pdf</th>"; echo "</tr>"; while($row=mysql_fetch_array($result)){ echo "</td><td>"; echo $row['event_type']; echo "</td><td>"; echo $row['client']; echo "</td><td>"; echo $row['incident_date']; echo "</td><td>"; echo $row['responders']; echo "</td><td>"; echo $row['location']; echo "</td><td>"; echo $row['word_document']; echo "</td><td>"; echo $row['pdf_document']; echo "</td></tr>"; } echo "</table>"; ?> Hope this helps? Link to comment https://forums.phpfreaks.com/topic/260365-file-location-stored-in-database-retrieval-to-html/#findComment-1334711 Share on other sites More sharing options...
samshel Posted April 5, 2012 Share Posted April 5, 2012 Is the path for the document in web directory? I mean is it in a directory which is accessible by browser? If yes, you can do some thing like this: while($row=mysql_fetch_array($result)){ echo "</td><td>"; echo $row['event_type']; echo "</td><td>"; echo $row['client']; echo "</td><td>"; echo $row['incident_date']; echo "</td><td>"; echo $row['responders']; echo "</td><td>"; echo $row['location']; echo "</td><td><a href='".$siteURL.$row['word_document']."'>Click Here</a>"; echo "</td><td>"; echo "</td><td><a href='".$siteURL.$row['pdf_document']."'>Click Here</a>"; echo "</td></tr>"; } Where $siteURL full web browsable URL of the PDF file. I tried appending the path to the domain you suggested but gave 404 so i assume it is not in web directory in private folder. assuming Link to comment https://forums.phpfreaks.com/topic/260365-file-location-stored-in-database-retrieval-to-html/#findComment-1334762 Share on other sites More sharing options...
carterlangley Posted April 5, 2012 Author Share Posted April 5, 2012 Hi Samshel That worked exactly how I wanted it to. Go have a look. Thank you! I adjusted the location of the files and all works fine. I have added that little snippet of code to my ever growing code base for future use. Thanks again. Carter Link to comment https://forums.phpfreaks.com/topic/260365-file-location-stored-in-database-retrieval-to-html/#findComment-1334804 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.