php_beginner_83 Posted September 29, 2009 Share Posted September 29, 2009 Hi Everyone I'm trying to loop through an array of images that I create from getting the image paths from a database and am having problems getting it to work...any ideas? Thanks $result = mysql_query("SELECT * FROM pictures INNER JOIN pics_in_albums ON pictures.ID = pics_in_albums.PicID INNER JOIN albums ON pics_in_albums.AlbumID = albums.ID WHERE albums.ID = 1") or die(mysql_error()); $paths = array(); $counter = 0; //fetch tha data from the database while ($row = mysql_fetch_assoc($result)) { $currentImage = "images//" . substr(strrchr($row['Path'],92),1); $counter++; if ($counter % 3 == 0) { echo '<a href=#><img src="thumb.php?image=$currentImage alt="" /></a><br/>'; } else { echo '<a href=#><img src="thumb.php?image=$currentImage" alt="" /></a>'; } } ?> However, when I explicitly type in the name of the image it works fine and creates the thumbnail.. <img src="thumb.php?image=beach.jpg alt="" /> Thanks. Link to comment https://forums.phpfreaks.com/topic/175946-getting-value-from-database-and-pass-it-to-php-page/ Share on other sites More sharing options...
herghost Posted September 29, 2009 Share Posted September 29, 2009 Try This. <?php $result = mysql_query("SELECT * FROM pictures INNER JOIN pics_in_albums ON pictures.ID = pics_in_albums.PicID INNER JOIN albums ON pics_in_albums.AlbumID = albums.ID WHERE albums.ID = 1") or die(mysql_error()); $paths = array(); $counter = 0; //fetch tha data from the database while ($row = mysql_fetch_assoc($result)) { $currentImage = "images//" . substr(strrchr($row['Path'],92),1); $counter++; if ($counter % 3 == 0) { echo "<a href=#><img src='thumb.php?image=$currentImage' alt='' /></a><br/>"; } else { echo "<a href=#><img src='thumb.php?image=$currentImage' alt='' /></a>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/175946-getting-value-from-database-and-pass-it-to-php-page/#findComment-927118 Share on other sites More sharing options...
php_beginner_83 Posted September 29, 2009 Author Share Posted September 29, 2009 Thanks for the suggestion. I tried it and it's still not working Link to comment https://forums.phpfreaks.com/topic/175946-getting-value-from-database-and-pass-it-to-php-page/#findComment-927123 Share on other sites More sharing options...
cags Posted September 29, 2009 Share Posted September 29, 2009 Just incase anybody else is wondering what herghost was suggesting (took me awhile to spot the difference, maybe I'm just slow), they have basically switched the single and double quotes over on the rows of code that echo out anchor links. <?php $var = "Test"; echo '$var'; // will give an output of $var echo "$var"; // will give an output of Test ?> Also in the OP's code, the src attribute of the first anchor tag didn't have a closing quotation anyway. I should also point out that the href attribute doesn't have quote's around it in either post, which I assume it should have. <?php if ($counter % 3 == 0) { echo '<a href="#"><img src="thumb.php?image="'. $currentImage .'" alt='' /></a><br/>'; } else { echo '<a href="#"><img src="thumb.php?image="'. $currentImage .'" alt='' /></a>'; } ?> Note: I changed the order back, for no other purpose than thats my prefered method, the way herghost suggested should have been fine. If this doesn't work, I suggest you look at the outputted HTML and check if the value you have in the src attribute looks correct and is in the form of (what I'm presuming was the correct format) of "thumb.php?image=beach.jpg". Link to comment https://forums.phpfreaks.com/topic/175946-getting-value-from-database-and-pass-it-to-php-page/#findComment-927130 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.