How do i check if sql field is empty.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anticore
Forum Newbie
Posts: 21
Joined: Sat Mar 11, 2006 11:37 pm

How do i check if sql field is empty.

Post by anticore »

Code: Select all

while ($row = mysql_fetch_array ($r)) 
		{ 
    		print "<center>{$row['name']}<br><br>";
			print "<IMG SRC=\"{$row['image1']}\"></center><br>";
			print "<br>";
			print "Year: {$row['year']}"; 
			print "<br><br>";
			print "{$row['details']}";
			print "<br><center><br>";
			print "<IMG SRC=\"{$row['image2']}\"><br>";
			print "<IMG SRC=\"{$row['image3']}\"><br>";
			print "<IMG SRC=\"{$row['image4']}\"><br>";
			print " </center>";
 		}
I want this while script only to print image4 if it finds one. can i embed an if statement within the loop?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yes, you can have an if statement inside a loop.
anticore
Forum Newbie
Posts: 21
Joined: Sat Mar 11, 2006 11:37 pm

Post by anticore »

Code: Select all

while ($row = mysql_fetch_array ($r))  
        {  
            print "<center>{$row['name']}<br><br>"; 
            print "<IMG SRC=\"{$row['image1']}\"></center><br>"; 
            print "<br>"; 
            print "Year: {$row['year']}";  
            print "<br><br>"; 
            print "{$row['details']}"; 
            print "<br><center><br>"; 
            print "<IMG SRC=\"{$row['image2']}\"><br>"; 
            print "<IMG SRC=\"{$row['image3']}\"><br>"; 
                  if ({$row['image4']}==0)
                       {
                           print " </center>";
                        }else {
                                     print "<IMG SRC=\"{$row['image4']}\"><br>"; 
                                     print " </center>"; 
                                  }
         }
would this work?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Have you tried it?
anticore
Forum Newbie
Posts: 21
Joined: Sat Mar 11, 2006 11:37 pm

Post by anticore »

yea that one didnt work to well
but this one does the job

Code: Select all

if ($row['image4']=="") 
                       { 
                           print " </center>"; 
                        }else { 
                                     print "<IMG SRC=\"{$row['image4']}\"><br>";  
                                     print " </center>";  
                                  } 
         }
Post Reply