alexsmith2709 Posted July 20, 2011 Share Posted July 20, 2011 Hi, What im trying to do may be a complicated way so if anyone can point me in the direction of a simpler way please advise. I have an image upload script which works fine, but i'd like the images to appear on a webpage without manually adding the img src to the webpage code. I have code which will add the filename to a database but i cannot seem to retrieve the filename from the database. My code is: <?php include("includes.php"); doConnect(); $get_image = "SELECT image FROM images"; $result= mysqli_query($mysqli, $get_image) or die(mysqli_error($mysqli)); while ($row = mysqli_fetch_array($result)) { echo "<img src=urbanimage.php?Ref=".$row['image'].">"; } ?> What im getting at the moment is "; } ?> as the output with an image placeholder before it. The url of the image is urbanimage.php?Ref=%22.$row['image'].%22 The image name is meant to be after the Ref= so the displayed image url should be urbanimage.php?Ref=imagename.jpg I have tried numerous things with no luck. I have made sure the database login details are correct. Thanks, Alex Quote Link to comment https://forums.phpfreaks.com/topic/242430-retrieve-from-a-database/ Share on other sites More sharing options...
AyKay47 Posted July 20, 2011 Share Posted July 20, 2011 what you are doing is using a url as the source, what you need to be doing is saving the file path to your db, then using that as the source.. eg.. $file_path = some/directory/to/file.jpg; // this should be in your db while ($row = mysqli_fetch_array($result)) { $file_path = $row['file_path']; //same as above, grabbing value from db and use it as img src echo "<img src=$file_path />"; } Quote Link to comment https://forums.phpfreaks.com/topic/242430-retrieve-from-a-database/#findComment-1245114 Share on other sites More sharing options...
alexsmith2709 Posted July 20, 2011 Author Share Posted July 20, 2011 I have a url as the source as i have an image watermark script. Before i had: <img src="urbanimage.php?Ref=image.jpg" alt="image"> which worked as i wanted, now instead of having to write each imagename in the codei want to have it get the name of each image from the database (or somehow get the names from a specific folder). My image upload script loads the image using the line: $im = imagecreatefromjpeg ('photos/urban/'.$_GET['Ref']); and then the watermark is added so unless i change the way of doing this i need to keep the urbanimage.php?Ref=image.jpg. Quote Link to comment https://forums.phpfreaks.com/topic/242430-retrieve-from-a-database/#findComment-1245130 Share on other sites More sharing options...
AyKay47 Posted July 20, 2011 Share Posted July 20, 2011 then you should be able to do this the way that you intended, need to change the concatenation a little...and make sure that your variable is printing out what is expected.. while ($row = mysqli_fetch_array($result)) { echo "<img src=urbanimage.php?Ref={$row['image']}>"; } Quote Link to comment https://forums.phpfreaks.com/topic/242430-retrieve-from-a-database/#findComment-1245142 Share on other sites More sharing options...
alexsmith2709 Posted July 20, 2011 Author Share Posted July 20, 2011 Thank you. I had tried something similar before. I found my underlying problem was that i had the PHP code in a HTML file, i have now changed the urban.html to urban.php and everything works. Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/242430-retrieve-from-a-database/#findComment-1245149 Share on other sites More sharing options...
AyKay47 Posted July 20, 2011 Share Posted July 20, 2011 no problem, please mark this as solved.. Quote Link to comment https://forums.phpfreaks.com/topic/242430-retrieve-from-a-database/#findComment-1245154 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.