Ok so I am deveopling a site for one of my clients, and I had to use some php I am not familiar with to do what he wants. Basically, all I am doing is displaying data from a mysql table on an html table on a website. However, one of the feilds is a BLOB and I am uploading pdfs to this feild. I need to be able to display them as a little pdf icon so they are downloadable. Currently, when I upload the pdf to the table, it is displayed all funky with tons of weirds characters. Here is one of the pages I am talking about. http://gator452.hostgator.com/~teiweb/?page_id=58 Where I currently have "test1,test2" etc is the feild where I need it to be downloadable. I need it like this page here, where they have "specs" as a downloadable file on each one. http://www.sinwan.com/sinwan_web/show_ac_list.asp?Type=Tubexial_Plastic_AC Here is the code I am currently using -----------------Here is the Code---------------------------- <?PHP # Param 1 : MySQL Host Name # Param 2 : MySQL Username # Param 3 : MySQL Password # Param 4 : MySQL Database # Param 5 : SQL Statement (SELECT) show_table("localhost","MYUSERNAME","MYPASS","MYDATABASE","SELECT * FROM MYTABLENAME"); function show_table($hostName,$userName,$passWord,$dataBase,$sqlQuery) { # Connect to MySQL $conn=mysql_connect($hostName,$userName,$passWord); # Select Database mysql_select_db($dataBase,$conn); # Validate SQL Statement $array=explode(" ORDER",$sqlQuery); $sqlQuery=$array[0]; if(!strstr($sqlQuery,"SELECT")) die("Invalid Query : SQL statement should be a SELECT statement."); # ORDER records by requested column if($_GET['order']) $sqlQuery=$sqlQuery." ORDER BY ".$_GET['order']; # Execute SQL query $result=mysql_query($sqlQuery) or die("Invalid Query : ".mysql_error()); $row=mysql_fetch_array($result); # Check whether NULL records found if(!mysql_num_rows($result)) die("No records found."); echo "<table border=1><tr>"; # Make the row for table column names while (list($key, $value) = each($row)) { $i++; if(!($i%2)) echo "<td><b><a href='?order=$key'>$key</a></td>"; } echo "</tr>"; $result=mysql_query($sqlQuery); // Make rows for records while($rec=mysql_fetch_array($result)) { echo "<tr>"; for($i=0;$i<count($rec);$i++) { if($rec[$i]) echo "<td>$rec[$i]</td>"; } echo "</tr>"; } echo "</table>"; } ?> ---------------------------------------------
first question would be, why are you storing the pdf in the database? upload the files to a location and record the filename for the pdf and then for that field output a link to the pdf. If you don't want them directly accessible, write another script to pull just the pdf location and download. Or if you must do it this way, you need to make another script to link and pull just the PDF. something like showpdf.php?id=1 and it doesn't include the HTML page, just the pdf.
Well see I made an admin area for the client so he can add products to the database on his own. So linking files and all that would probably be too complicated for him. How would I include showpdf.php?id=1 into my current script? Sorry I am new to php. Thanks so much for your help!
Don't think you understand. It wouldn't be any different than what you are currently doing as far as the client's concerned. All you would do on the current page is skip printing out the PDF and replace it with a link to a new script which only prints out the PDF. showpdf.php would be a new page (php script) and the id would be equal to whatever the current records ID is. THat is assuming you have assigned a unique id to each record.