Page 1 of 1

ifelse

Posted: Fri May 15, 2009 1:35 pm
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 -->

Re: ifelse

Posted: Fri May 15, 2009 1:41 pm
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...