Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/242430-retrieve-from-a-database/
Share on other sites

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 />";
}

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.

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']}>";
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.