jdv Posted May 13, 2020 Share Posted May 13, 2020 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 />'; Quote Link to comment Share on other sites More sharing options...
requinix Posted May 13, 2020 Share Posted May 13, 2020 $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. 2 Quote Link to comment Share on other sites More sharing options...
jdv Posted May 13, 2020 Author Share Posted May 13, 2020 Thanks , I already solved this with a for loop and fetching the query to an array. Quote Link to comment Share on other sites More sharing options...
requinix Posted May 13, 2020 Share Posted May 13, 2020 Well, nice to know we both had the same answer. Quote Link to comment 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.