Geek Geek - 1 year ago 84
PHP Question

Display html in echo statement

Ok the below information works im just trying to figure my problem is that if
that it displays like this
title grade...

but i want to put a | inbetween like this

title | grade.

my below code works but if there is no grade it still echos the |,

how can i get it to only echo when there is a value in that field.

because when the field is empty it shows

title |

<div class="sto-info">
<span><?php echo $title; ?> <?php echo '|', $grade; ?></span>

Answer Source

You can use a ternary operator:

<span><?php echo $title; ?> <?php echo $grade ? '|' . $grade : ''; ?></span>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download