teknospr Posted March 6, 2011 Share Posted March 6, 2011 Good day: Im trying to display an image from a folder and the image name is retrieved by a query. The query is getting the image name all right but the image is not displaying. This is the code im using for the image display <?php $aid = 1; $connection = mysql_connect("localhost", "username", "password"); mysql_select_db("articles", $connection); $query="SELECT imagename, description FROM articles_description WHERE id='$aid'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table width ="1000" border="1" cellspacing="2" cellpadding="2"> </tr> <?php $j=0; while ($j < $num) { $f8=mysql_result($result,$i,"description"); $f9=mysql_result($result,$i,"imagename") ?> <tr> <td valign="top"> <img src="images/'.$f9.'; ?>" alt="" name="picture" width="100" height="100" border="1" /></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f8; ?></font></td> </tr> <tr> </tr> <?php $j++; } ?> Any help will be appreciated Link to comment https://forums.phpfreaks.com/topic/229776-displaying-image-from-folder/ Share on other sites More sharing options...
Pikachu2000 Posted March 6, 2011 Share Posted March 6, 2011 You aren't actually echoing the image name from the variable into the markup. If you View--->Source, you'll see the literal string src="images/' .$f9. '; ?>" where the filename should be. Link to comment https://forums.phpfreaks.com/topic/229776-displaying-image-from-folder/#findComment-1183587 Share on other sites More sharing options...
teknospr Posted March 6, 2011 Author Share Posted March 6, 2011 How do I fix this? Link to comment https://forums.phpfreaks.com/topic/229776-displaying-image-from-folder/#findComment-1183593 Share on other sites More sharing options...
Pikachu2000 Posted March 6, 2011 Share Posted March 6, 2011 By echoing the variable from within php instead of using it as a string literal in the markup. You know how to go into and out of PHP and how to echo a variable, right? <img src="images/" <?php echo $f9; ?>" alt="" name="picture" width="100" height="100" border="1" /> Link to comment https://forums.phpfreaks.com/topic/229776-displaying-image-from-folder/#findComment-1183597 Share on other sites More sharing options...
teknospr Posted March 6, 2011 Author Share Posted March 6, 2011 Thanks. tweaked it a little and it worked. <td><img src="images/<?php echo $f9; ?>"alt="" name="picture" width="130" height="100" border="1" /></td> Link to comment https://forums.phpfreaks.com/topic/229776-displaying-image-from-folder/#findComment-1183612 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.