Possible Coding Help...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tattooartist
Forum Newbie
Posts: 18
Joined: Thu Feb 17, 2011 3:59 pm

Possible Coding Help...

Post by tattooartist »

Could some one please guide me to a possible script to accomplish this task....

I want to pull and display two separate things that are in two separate places and display them as one link on a page. I have figured out how to display the data to a page and also how to display the files to a page separately but need to accomplish this and join the 3 things together.

I have a library table in the database that stores the product_code and product_name
example:

pk-pen(product_code) traditional fountain pen(product_name) ---- (this is where I need to get the data from)

Then I have a folder on the server that is called library that has the pdf files in it. Each pdf file has the same name as the product_code that is in the database.
example:
pk-pen_ins.pdf

What I need to accomplish is grabbing the product_code and product_name for the database and then go to the folder on the server and add the correct pdf file with that data and display it as a link on a page for customers to download. bee struggling with this and pasted code that i have to do each task separately but cant seem to get it all in one script to do the above. I understand that this could be asking for a lot here but I am new to this and would be forever in debt to your kindness. Thanks on this in advance
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: Possible Coding Help...

Post by danwguy »

I would use something like this...

Code: Select all

$results = mysql_query("SELECT * FROM tablename") or die("Could not SELECT: " .mysql_error());
while($row = mysql_fetch_array($results)) {
$file = $row['product_code'];
$name = $row['product_name'];
}
echo "<a href='" . $file . "'.pdf'>$name</a><br />";
that will scan the database and return all of the product_code and product_name results then show a link to whatever is stored in product_code with a .pdf on the end of it.
Obviously replace tablename with your tablename.
Hope that helps, if you need something different let me know and I'll work on it.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Possible Coding Help...

Post by social_experiment »

Code: Select all

$results = mysql_query("SELECT * FROM tablename") or die("Could not SELECT: " .mysql_error());
while($row = mysql_fetch_array($results)) {
$file = $row['product_code'];
$name = $row['product_name'];
}
echo "<a href='" . $file . "'.pdf'>$name</a><br />";
The OP would probably have to move the last line inside the while loop or there will be only 1 hyperlink displayed. :)
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: Possible Coding Help...

Post by danwguy »

good call man, my brain was just not functioning yesterday. :dubious:
Post Reply