Jump to content

Retrieving file location from database


RobertFullmen

Recommended Posts

Hey all,

I've written a php search feature for a mysql database. The search returns a file name like sample.gif, how would I go about displaying the actual image instead? Since the images all have the same location could I have the search return the string into a variable then make the whole thing a link? Thanks.

Link to comment
Share on other sites

Hi

 

More of a php question really.

 

However something like this would be required.

 

$sql = 'SELECT ImageName, ImageAltTag FROM Images';

$result = mysql_query($sql);

while($row = mysql_fetch_assoc($result))
{
echo '<img src="'.$row['ImageName'].'" alt="'.$row['ImageAltTag'].'" /><br />';
}

 

That will put out all the images on the database onto the screen.

 

If the images are in a standard sub directory somewhere (say 'images') them just change it to

 

$sql = 'SELECT ImageName, ImageAltTag FROM Images';

$result = mysql_query($sql);

while($row = mysql_fetch_assoc($result))
{
echo '<img src="images/'.$row['ImageName'].'" alt="'.$row['ImageAltTag'].'" /><br />';
}

 

All the best

 

Keith

Link to comment
Share on other sites

I got it! Thanks so much for the help everyone. I was over thinking it a bit, here's what worked:

$data = mysql_query("select * FROM Inventory WHERE img1 LIKE 'Searchterm'")
or die(mysql_error()); 


while($info = mysql_fetch_array( $data )) 
{ 
echo '<img src="images/'.$info['img1'].'"><br />';
} 

Link to comment
Share on other sites

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.