Jump to content

PHP retrieving images corresponding to MySQL table


jdv

Recommended Posts

Hello Guys,

I need help on this problem.

output:

display images for the values that exist in the table:

input:

the values in a table's column where they're in the format of "0,0" and the image corresponding to it is named 0,0.png

this is my attempt $q is retrieving "0,0" however in order for me to retrieve its image i need to add ".png" to it in order to find it in the directory that the image is located. It tried without ".png" and it also doesn't work.

$q = 'SELECT ID FROM table'; 
   $dirname = "directory/";
   $images = glob($dirname.$q.".png");
   foreach($images as $image) {
    echo '<img src="'.$image.'" /><br />';

 

Link to comment
Share on other sites

$q = 'SELECT ID FROM table';

That is a SQL query. You have to run that query through your database, receive the results, and then look for each single matching image in the directory for every returned record.

You can probably skip looking in the directory, though. It will only tell you if the file exists. So if you already know (or assume) the file exists then you don't need to bother looking.

  • Like 2
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.