LiamH Posted July 21, 2009 Share Posted July 21, 2009 Hi all. I'm adding bits and pieces to my website, and one improvement is going to be a image viewer. I have an article table in my database which has a section where you can put the names of images that are to be used in the article. These images will then be printed underneath the article, and eventually have a link which will open up the image viewer, and display the images associated with that article. So for example, the article table has column called screen1, just for testing purposes. In this there is a row that has the position of the image in the server. For example /images/image1.jpg. If no screenshots are required, the field is left blank. Now in the actual code for the article page I have the following; if (mysql_num_rows($res1) > 0) { while($row = mysql_fetch_assoc($res1)) { echo stripslashes("<img src=".$row['screen1'].">"); } } Now there is evidently something wrong with what I have done somewhere, as the code automatically prints the <img> even if there is no image associated with the article in the database. Where have I gone wrong please? Link to comment https://forums.phpfreaks.com/topic/166792-solved-if-statement-not-working-correctly/ Share on other sites More sharing options...
rhodesa Posted July 21, 2009 Share Posted July 21, 2009 why are you using strip slashes? also, you need an if on the field: if (mysql_num_rows($res1) > 0) { while($row = mysql_fetch_assoc($res1)) { if($row['screen1']){ echo "<img src=".$row['screen1'].">"; } } } Link to comment https://forums.phpfreaks.com/topic/166792-solved-if-statement-not-working-correctly/#findComment-879503 Share on other sites More sharing options...
LiamH Posted July 21, 2009 Author Share Posted July 21, 2009 Thanks very much Link to comment https://forums.phpfreaks.com/topic/166792-solved-if-statement-not-working-correctly/#findComment-879513 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.