[EMAIL PROTECTED] wrote:

> I have a pdfs/documents saved in a field called 'content' on my db and I
> want to create an active hyperlink so users can download. any ideas how I
> can achive this.
> 
> I am sure it is simple but cannot find an easy example posted.
> 
> thanks,
> 
> Ross

Hi Ross,

Answered you in the PHP group, but this is a different query. Here is the
PHP and MySQL I use to do the same thing. I see no reason not to use HTML
to create links to download your pdf files by the way. It keeps things
simple.

You do mean that you keep the filenames in the database, right? 

Feel free to email if you want some explanation, as it seems we are doing
the same thing.

                /*
                 *Construct MySQL query
                 */

   $query = array_pop($queries);
   
                    $select = "SELECT files.*";
                    $from = "\nFROM files, assoc, words";
                    $where = "\nWHERE words.word = '" . $query . "' AND ";
                    $where .= "words.id = assoc.word_id \nAND";
                    $where .= " assoc.file_id = files.id ";


                   foreach ($queries as $q)
                   {
                        $from .= ",\nassoc AS assoc_$q, ";
                        $from .= " words AS words_$q";
                        
                        $where .= "\n AND words_$q.word = '" . $q . "'";
                        $where .= "\nAND \nwords_$q.id = assoc_$q.word_id
\nAND ";
                        $where .= "assoc_$q.file_id = files.id ";
                       }
                       if ((isset($startdate) and isset($enddate)) or
($startdate != "" and $enddate != ""))
                    {
                      $where .= " \nAND \nfiles.startdate <= '$enddate'
\nAND ";
                      $where .= "files.enddate >= '$startdate'";
                      }
                      $order = "\n ORDER BY files.series, files.volume";     
        
                    /*
                 * connect to database
                 */
                   $conn = mysql_connect($dbhost, $dbuser, $dbpass);
                   if (!$conn)
                   {
                                die("couldn't connect to $dbhost");
                   }
                   if (!mysql_select_db($dbname, $conn))
                   {
                                die(mysql_error($conn));
                   }


        /*
                 construct query
        */
                   $selectq = $select . $from . $where . $order;
                   echo " <!--MySQL query: $selectq -->\n";
                   $res = mysql_query($selectq, $conn);
                   if (!$res)
                   {
                   die(mysql_error($conn));
                   }

                        /*
                        * Output the results to browser
                        */
                        
/*
* Create HTML table for results
*/
        echo "<table class=\"results\">";
        echo
"<tr><td><strong>Source</strong></td><td><strong>Volume</strong></td><td><strong>Start
date</strong></td><td><strong>End date</strong></td></tr>\n";

          while ($line = mysql_fetch_array($res, MYSQL_ASSOC))
                {
                echo "<tr><td><a
href=\"$line[file]\">$line[series]</a></td><td>$line[volume]</td><td>$line[startdate]</td><td>$line[enddate]</td></tr>\n";
                }

mysql_close($conn);
echo "</table>";

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to