PDA

View Full Version : Info on serving up docs from MySQL database


RobWNY
05-19-2011, 04:23 PM
I'm sure this is very basic for most, but this is my first go at this... I'm only asking to be pointed in the right direction, not looking for excessive hand holding.

I have created a table in MySQL for documents I wish to serve up (PDFs, MS word, Excell, etc...). It contains fields for the DocName and DocLocation (dir. path on the web server), as well as a few others... I can display the data in live view after a record set query in DW. What I can't seem to figure is how to create a link that uses the directory path of a given doc name, so I can serve up the various documents via the database. I've look at DW help files and Googled for answers, but i fear I'm not searching using the correct terminology key words.

Any guidance is greatly appreciated.

edbr
05-20-2011, 03:06 AM
it depends how your page is coded but see if this makes sense.

your fields from the database are(for example) $row['path'] and
$row['file'].
you can concanate them like this
$path= $row['path'] .$row['file'];
the a link would be <a href=" <?php echo $path : ?>"><?php echo $path : ?></a>

RobWNY
05-21-2011, 03:20 PM
edbr,

First of all, thanks for taking the time to reply. You're the only one so far from 5 different forum post who has.

I'm able to successfully perform a SQL query through phpmyadmin that gets me the concatenated results I'm looking for.

SELECT CONCAT(`DocLocation`,'/',DocName) Doc_Link
FROM efi_docs ORDER BY DocName

The problem is I can't seem to get either of the following to occur.
Figure out how to make the query above feed the results to a new/or other existing field/column in that or another table.
When making the same query from a advanced record set (query) within the Bindings panel in Dreamweaver (CS3) it does display the correct results when hitting the test button. However, I can't get it to work successfully as a link.

I've played around a bit by scraping together things read from other posts, but the best I get is a PDF downloaded that is corrupt and unreadable by Acrobat. Thanks for any future input.

mangofreak
05-21-2011, 10:49 PM
I believe EDBR is telling you to concatenate on the web page not on your SQL statement.

If all the documents are stored in the same directory, you could just:

<a href="yourpath/<?php echo 'your-file.doc')?>">filename</a>

Does it make any sense?

RobWNY
05-22-2011, 02:40 PM
I believe EDBR is telling you to concatenate on the web page not on your SQL statement.

If all the documents are stored in the same directory, you could just:

<a href="yourpath/<?php echo 'your-file.doc')?>">filename</a>Does it make any sense?


Many different directories.

mangofreak
05-22-2011, 04:58 PM
What do you have so far? did you try applying EDBR's suggestion? Show us your code that may help

davidj
05-24-2011, 02:45 PM
Agreed

I would code the path from within the page not the database

in your db you could have a path code field where when reading it you could create a switch which would define your document base path


// in this example 1,2,3 would be stored in the table based on the doc type.
// This could be inserted in the table on a document upload.

switch($pathCode){

case '1': $basePath = "documents/pdf/"; break;
case '2': $basePath = "documents/word/"; break;
case '3': $basePath = "documents/text/"; break;

}

// you can use $basePath in your path structure