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>"; } Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 3, 2009 Share Posted April 3, 2009 Good to hear you got it sorted 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.