ifelse

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
randall
Forum Newbie
Posts: 16
Joined: Fri May 08, 2009 9:01 pm

ifelse

Post by randall »

There are two snippets here...

I know there is a better way of doing this using ifelse but I can not get it to work... I feel as if I am just writing too much code to do some simple task... can someone help me with a better way of doing this?

Code: Select all

<?php 
if (!$name) { 
echo "<center>The product you requested is no longer available. Please feel free to look around at some our other great products.</center>"; 
}
else { 
echo "Product:";
} 
?>
</b></font>
 
<font color="#000000" size="-1" face="Arial, Helvetica, sans-serif">
<?php 
if (!$name) { 
echo " "; 
}
else { 
echo "$name"; 
}
?>
</font> 
 
<font color="#6B1810" size="-1" face="Arial, Helvetica, sans-serif"><b>
<?php 
if (!$name) { 
echo " "; 
}
else { 
echo "<br>"; 
}
?>
</b></font>
<!--End Name -->
and this one...

Code: Select all

<!--Artist -->
<font color="#6B1810" size="-1" face="Arial, Helvetica, sans-serif"><b>
<?php 
if (!$art) { 
echo " "; 
}
else { 
echo "Artist:";
} 
?>
</b></font>
 
<font color="#6B1810" size="-1" face="Arial, Helvetica, sans-serif"><b>
 
<?php
if ($art=Unknown) { 
echo " "; 
}
else { 
echo "Artist: ";
} 
?>
</b></font>
 
<?php
if ($art=Unknown) { 
echo " "; 
}
else { 
echo "$artist";
} 
 
?>
 
<?php 
if (!$art) { 
echo " "; 
}
else { 
echo "$artist"; 
}
?>
 
<?php 
if (!$art) { 
echo " "; 
}
else { 
echo "<br>"; 
}
?>
<!--End artist -->
Last edited by Benjamin on Fri May 15, 2009 3:03 pm, edited 1 time in total.
Reason: Changed code type from text to php.
crazycoders
Forum Contributor
Posts: 260
Joined: Tue Oct 28, 2008 7:48 am
Location: Montreal, Qc, Canada

Re: ifelse

Post by crazycoders »

You don't have too much code here it seems. You can probably just put it in less lines such as:

Code: Select all

<font><?php if(!$name){ ?><?php }else{ ?></font>
etc...

PS: FONT tags are not recommended anymore, use SPAN with inline Styles or SPAN with classes...
Post Reply