mrkfox Posted May 9, 2009 Share Posted May 9, 2009 Hi I am trying to display some images on a page using PHP. The image url (/images/products/imagename.jpg) is stored in a database. How would i go about displaying the image on my html page? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/157521-php-and-displaying-images/ Share on other sites More sharing options...
gevans Posted May 9, 2009 Share Posted May 9, 2009 Is the image stored in a database, or is the image filename stored in the database? Link to comment https://forums.phpfreaks.com/topic/157521-php-and-displaying-images/#findComment-830495 Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 gevans, he said the image url is stored in the database. Run a SQL that gets the image and just write it out. Link to comment https://forums.phpfreaks.com/topic/157521-php-and-displaying-images/#findComment-830496 Share on other sites More sharing options...
mrkfox Posted May 9, 2009 Author Share Posted May 9, 2009 The actual images are stored in /images/products. The database only stored the image location for example: /images/products/imagename.jpg Forgot to say i have multiple images in my database and i would like them all displayed on my page. Link to comment https://forums.phpfreaks.com/topic/157521-php-and-displaying-images/#findComment-830497 Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 Then run a SQL that gets them all. Link to comment https://forums.phpfreaks.com/topic/157521-php-and-displaying-images/#findComment-830501 Share on other sites More sharing options...
mrkfox Posted May 9, 2009 Author Share Posted May 9, 2009 I've managed to get the data from the database and have assigned it to some variables. This is what I'm trying to use to display all of it: echo "<b>$name</b><br>$description<br>genre<br>£$price<br>$stock<br><img src='$image' /><br>"; everything gets displayed successfully except for the image. Any help? Link to comment https://forums.phpfreaks.com/topic/157521-php-and-displaying-images/#findComment-830505 Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 Can you verify the URL for the images are correct? Link to comment https://forums.phpfreaks.com/topic/157521-php-and-displaying-images/#findComment-830511 Share on other sites More sharing options...
mrkfox Posted May 9, 2009 Author Share Posted May 9, 2009 If i take out the image tags the image url gets displayed correctly. I have triple checked that the images are in the correct location and the datbase contains the correct paths to the images. Link to comment https://forums.phpfreaks.com/topic/157521-php-and-displaying-images/#findComment-830516 Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 Can you post the output of that echo? Link to comment https://forums.phpfreaks.com/topic/157521-php-and-displaying-images/#findComment-830519 Share on other sites More sharing options...
mrkfox Posted May 9, 2009 Author Share Posted May 9, 2009 Link to comment https://forums.phpfreaks.com/topic/157521-php-and-displaying-images/#findComment-830521 Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 No I mean the HTML. Thanks! Link to comment https://forums.phpfreaks.com/topic/157521-php-and-displaying-images/#findComment-830523 Share on other sites More sharing options...
mrkfox Posted May 9, 2009 Author Share Posted May 9, 2009 I basically have a button in a form on the simplest html page possible which when clicked goes to a displayproducts.php and then the data gets displayed. Link to comment https://forums.phpfreaks.com/topic/157521-php-and-displaying-images/#findComment-830534 Share on other sites More sharing options...
gevans Posted May 9, 2009 Share Posted May 9, 2009 When you're on the page, right click and hit 'view source' and post the html! Link to comment https://forums.phpfreaks.com/topic/157521-php-and-displaying-images/#findComment-830535 Share on other sites More sharing options...
mrkfox Posted May 9, 2009 Author Share Posted May 9, 2009 Figured it out finally after 2 hours. I had the paths saved in my database as /images/products/image.jpg and i had to have them as images/products/image.jpg. All i had to do was take the slash from the start of the path. Link to comment https://forums.phpfreaks.com/topic/157521-php-and-displaying-images/#findComment-830563 Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 -.- that was the whole point I asked you for the HTML. Link to comment https://forums.phpfreaks.com/topic/157521-php-and-displaying-images/#findComment-830568 Share on other sites More sharing options...
mrkfox Posted May 9, 2009 Author Share Posted May 9, 2009 thanks for ya help i guess it's all good now. Link to comment https://forums.phpfreaks.com/topic/157521-php-and-displaying-images/#findComment-830570 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.