justin007 Posted May 23, 2013 Share Posted May 23, 2013 I am looking for some guidance before i attampt to code the following. The Brief: I have a MySQL database of music, one of the columns is called "albumart", within this entry is a file name i.e. "picture.jpg". This entry is not a link... just a file name. I would like to display picture.jpg onto my website. The picture is stored in a specific location on the server. This is what i think i need to do: Call the "albumart" columns most recent entry into a variable (i think) , then ask PHP to go and find the "file name" from a specific location (on the server) add it to another variable (i think) and then display it on screen. I hope this makes sense... although i understand the basic concept i am unsure where to start when it comes to linking the two bits of code together much respect... justin.. Quote Link to comment https://forums.phpfreaks.com/topic/278313-i-need-to-display-an-image-from-my-ftp-using-a-database-entry-result-php-mysql/ Share on other sites More sharing options...
Muddy_Funster Posted May 23, 2013 Share Posted May 23, 2013 You would need to have the images stored in a folder that is accessable through the webserver software using a path. if this is a fixed location then you can just hard code it, if it is dynamic then you really should be storing it in the database attached to the image. What is your full current setup? Quote Link to comment https://forums.phpfreaks.com/topic/278313-i-need-to-display-an-image-from-my-ftp-using-a-database-entry-result-php-mysql/#findComment-1431780 Share on other sites More sharing options...
justin007 Posted May 23, 2013 Author Share Posted May 23, 2013 Hi Muddy_ I have mysql, php, apache all setup and running on a localhost enviroment. All the images will be stored on my server (in the htdocs folder) therefore a fixed location. The database stores the filename of each picture but nothing else. thanks... Justin. Quote Link to comment https://forums.phpfreaks.com/topic/278313-i-need-to-display-an-image-from-my-ftp-using-a-database-entry-result-php-mysql/#findComment-1431785 Share on other sites More sharing options...
Muddy_Funster Posted May 23, 2013 Share Posted May 23, 2013 well if it's in the root htdocs folder then all you need to do is get the file names from the database and use them in the src of the image elements of the page with a leading "/" something a bit like the following <?php $con = new PDO("mysql:host=localhost;dbname=yourDBname","username", "password"); $sql = SELECT name NAME images; $con->execute($sql); $result = $con->fetchAll(PDO::FETCH_ASSOC); foreach ($result as $row){ echo "<img src=\"/{$row['name']}\" alt=\"\" />"; } ?> That is over simplified but shouldn't be a million miles away. Quote Link to comment https://forums.phpfreaks.com/topic/278313-i-need-to-display-an-image-from-my-ftp-using-a-database-entry-result-php-mysql/#findComment-1431787 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.