Jump to content

file location stored in database retrieval to html


carterlangley

Recommended Posts

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.

 

 

 

 

 

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?

 

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

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

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.