fat creative Posted June 6, 2008 Share Posted June 6, 2008 I am trying to call in image from my database and it's just not working. I get no image. My page is at www.FatCreative.com/GFF and the images that aren't displaying are at the bottom of the page. When I code the name of the image, it works fine, but when I try to change the image name to the variable, I get a blank box. I'm sure it's something so simple. I've had tried dozens of different variations and I am either getting nothing or an error message. I have confirmed the variable name is showcase_image all lowercase. This is my code: echo "<table cellspacing=\"15\">\n"; while($row = mysql_fetch_assoc($result)) { extract($row); echo "<tr><td>"; echo "<img src=\"$showcase_image\" width=\"100\" height=\"100\" align=\"middle\" >"; echo " $prop_title<br />"; echo "$prop_desc<br />"; echo "<a href=\"showdetails.php?id_number=$id_number\"><div align=\"right\">View Details</div></a>"; echo "</td></tr>\n"; } echo "</table>\n"; Does anyone have any ideas? I am just learning PHP (and loving it!) but some of these things are so frustrating. Quote Link to comment https://forums.phpfreaks.com/topic/109068-echoing-an-image-as-a-variable/ Share on other sites More sharing options...
eRott Posted June 6, 2008 Share Posted June 6, 2008 Well, you are going to have to paste more code then that. Where are your queries, what are the names of your DB tables? Try something like this. Just use it as a guideline. Considering I do not know the names of your database tables, make sure to replace the appropriate values. $query = "SELECT * FROM TABLENAME"; $result = mysql_query($query) or die(mysql_error() . "<pre>$query</pre>"); echo "<table cellspacing=\"15\">"; while($row = mysql_fetch_array($result)) { echo '<tr><td>'; echo '<img src="'.$row[showcase_image].'" style="width: 100px; height: 100px; vertical-align: middle; padding-right: 5px;" >'; echo $row[prop_title].'<br />'.$row[prop_desc].'<br />'; echo '<div style="text-align: right;"><a href="showdetails.php?id_number='.$row[id_number].'">View Details</a></div>'; echo "</td></tr>"; } echo "</table>"; If this has solved your problem, please do not forget to mark the topic as solved. You will find the button on the bottom left of the page. Take care. Quote Link to comment https://forums.phpfreaks.com/topic/109068-echoing-an-image-as-a-variable/#findComment-559542 Share on other sites More sharing options...
fat creative Posted June 7, 2008 Author Share Posted June 7, 2008 My apologies. The newbieness prevents me from knowing what is too little to copy vs too much. This is the query part of the code: $query = "SELECT * FROM GFF WHERE featured_site = 'yes'"; $result = mysql_query($query) or die ("Couldnt execute query"); I did copy / paste what you suggested, but it still didn't return any images. This was the original code and the page is at www.fatcreative.com/GFF: <?php echo "<table cellspacing=\"15\">\n"; while($row = mysql_fetch_assoc($result)) { extract($row); echo "<tr><td>"; echo "<img src=\"$showcase_image\" width=\"100\" height=\"100\" align=\"middle\" >"; echo " $prop_title<br />"; echo "$prop_desc<br />"; echo "<a href=\"showdetails.php?id_number=$id_number\"><div align=\"right\">View Details</div></a>"; echo "</td></tr>\n"; } echo "</table>\n"; ?> I just can't see why this isn't working. Thank you again very much for any suggestions! Quote Link to comment https://forums.phpfreaks.com/topic/109068-echoing-an-image-as-a-variable/#findComment-559548 Share on other sites More sharing options...
digitalgod Posted June 7, 2008 Share Posted June 7, 2008 if you check your img src it looks like this Georgia Farm & Forest\Bartow\Bartow 9520\Images\IMGP1202.JPG I would suggest just having the name of the image in your database and then do this echo "<img src=\"images/$showcase_image\" width=\"100\" height=\"100\" align=\"middle\" >"; or wherever your images are located also it's much cleaner if you remove all those echo and do something like <table cellspacing="15"> <? while($row = mysql_fetch_assoc($result)) { extract($row); ?> <tr><td> <img src="<?=$showcase_image?>" width="100" height="100" align="middle" > <?=$prop_title?> <?=$prop_desc?> <a href="showdetails.php?id_number=<?=$id_number?>"><div align="right">View Details</div></a>"; </td></tr> <? } ?> </table> but that's just a matter of personal taste Quote Link to comment https://forums.phpfreaks.com/topic/109068-echoing-an-image-as-a-variable/#findComment-559555 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.