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
anticore
Forum Newbie
Posts: 21 Joined: Sat Mar 11, 2006 11:37 pm
Post
by anticore » Tue Mar 21, 2006 9:43 pm
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Mar 21, 2006 10:45 pm
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 » Wed Mar 22, 2006 4:28 pm
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Mar 22, 2006 4:34 pm
Have you tried it?
anticore
Forum Newbie
Posts: 21 Joined: Sat Mar 11, 2006 11:37 pm
Post
by anticore » Wed Mar 22, 2006 4:47 pm
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>";
}
}