Jump to content

Help Please.....


louroberto

Recommended Posts

OK i am trying to display a list on a page that displays a product code, product name and a pdf file. The product_code and product_name are in the database and the pdf files are in a folder on the server. I figured out how to display the data from the data base and also how to display the files from the directory folder. Where I am having trouble is getting the 2 scripts to work together. My end result would display a link on the page that would read like this

 

PK-PEN: Slimeline Pen Kit Instuctions (this would be a link to the pdf for download)

 

In the database there is also a file table that has the name of the pdf file with a file_id and this file_id is also in the library table where i am pulling the product_code and product_name from if that helps.

 

Here is my code for the data display

 

<?php
$username="";
$password="";
$database="";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM library";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<b>Pen Kits</b><br><br>";

$i=0;
while ($i < $num) {

$productcode=mysql_result($result,$i,"product_code");
$productname=mysql_result($result,$i,"product_name");




echo "<b>$productcode</b>: $productname</a><br>";

$i++;
}

?>

Here is the code for the pdf display from the directory....


<?php
$username="";
$password="";
$database="";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM library";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<b>Pen Kits</b><br><br>";



if ($handle = opendir('/home/httpd/vhosts/pennstateind.com/httpdocs/library/')) {
   while (false !== ($file = readdir($handle)))
      {
          if ($file != "." && $file != "..")
  {
          	$thelist .= '<a href="'.$file.'">'.$file.'</a>';
          }
       }
  closedir($handle);
  }



  
?>
<P>List of files:</p>
<P><?=$thelist?></p>

My question is how do I combine these 2 and make them return the result of a list that would display a link to download the PDF file.

 

I am new to PHP and any help would be great. Thank you in advance a million times over!!!!!

 

Lou

 

Link to comment
https://forums.phpfreaks.com/topic/227990-help-please/
Share on other sites

If I'm understanding you correctly there are two tables in the database one 'library' and one 'files'. If the library table contains an id referencing a file in the file table you could try joining the two tables together in a query and use the first part of your script for everything you need. You wouldn't have to browse the directory using the second part of your script.

 

Pseudo example:

 

$sql = "SELECT * FROM library l JOIN files F ON L.FILE_ID = F.FILE_ID";

 

Just a thought.

Link to comment
https://forums.phpfreaks.com/topic/227990-help-please/#findComment-1175656
Share on other sites

Yes there are two tables in the db one is library and the other is files which both contain a file_id. I need to grab the information but I also need to include in the displayed information which would be a list the pdf file that is attached to the product_code and that file is in a directory folder called library on the server. Sorry if my explanation is not clear but I am new to this and I greatly appreciate all the help. If I run the above select how would that actually display the pdf file from the directory folder and the correct prouduct code and name

Link to comment
https://forums.phpfreaks.com/topic/227990-help-please/#findComment-1175689
Share on other sites

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.