kev wood Posted April 3, 2009 Share Posted April 3, 2009 i have a CMS where the user has the option to upload an image to go with a news article. i had the problem where if they decided not to upload an image ie would put a red cross where the image was supposed to be. to work around this i tried to put an if statement in to stop the red cross if there was no image for that article. but all i have managed to do is stop all images being displayed. here is the code i have so far. $result = mysql_query("SELECT * FROM news ORDER BY id DESC") or die(mysql_error()); echo "<div style=\"height: 500px; width: 450px; overflow:auto;\">"; echo "<table width=350px border=0>\n"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['date']; echo "</td></tr>"; echo "<tr><td><b>"; echo $row['title']; echo "</b></td></tr>"; echo "<tr><td>"; if(!empty($row['image'])) { echo '<img src="images/'.$row['image'].'">'; } echo $row['article']; echo "</td></tr>"; echo"<tr><td> </tr></td>"; } Link to comment https://forums.phpfreaks.com/topic/152371-solved-image-not-showing/ Share on other sites More sharing options...
cs1h Posted April 3, 2009 Share Posted April 3, 2009 What I have done in the past is have a default image of 1px by 1px that is used if no image has been uploaded and is put in the table where you would record the data for an uploaded image. Link to comment https://forums.phpfreaks.com/topic/152371-solved-image-not-showing/#findComment-800210 Share on other sites More sharing options...
Yesideez Posted April 3, 2009 Share Posted April 3, 2009 Does "image" contain actualy image data or a filename? Link to comment https://forums.phpfreaks.com/topic/152371-solved-image-not-showing/#findComment-800215 Share on other sites More sharing options...
ranjuvs Posted April 3, 2009 Share Posted April 3, 2009 Hi kev wood, Change the portion if(!empty($row['image'])) { echo '<img src="images/'.$row['image'].'">'; } to $imgurl = "images/".$row['image']; if($row['image'] && file_exists($imgurl)) { echo "<img src=$imgurl>"; } let me know if the issue persists Regards Ranju Link to comment https://forums.phpfreaks.com/topic/152371-solved-image-not-showing/#findComment-800221 Share on other sites More sharing options...
kev wood Posted April 3, 2009 Author Share Posted April 3, 2009 thanks for the replies. sorry not replied sooner ws having a much needed dinner break. i will have ago at the fixes you have supplied and let you no what the out comes are. Link to comment https://forums.phpfreaks.com/topic/152371-solved-image-not-showing/#findComment-800226 Share on other sites More sharing options...
kev wood Posted April 3, 2009 Author Share Posted April 3, 2009 thanks again for the replies i have it working now with ranjuvs solution. cs1h your reply will probably be what i do in future. Yesideez i know it is a bit late to mention but yes the files name is held in the db and not the actual image its self. Link to comment https://forums.phpfreaks.com/topic/152371-solved-image-not-showing/#findComment-800232 Share on other sites More sharing options...
Yesideez Posted April 3, 2009 Share Posted April 3, 2009 Good to hear you got it sorted Link to comment https://forums.phpfreaks.com/topic/152371-solved-image-not-showing/#findComment-800235 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.