Geek Geek - 1 month ago 6x
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>


You can use a ternary operator:

<span><?php echo $title; ?> <?php echo $grade ? '|' . $grade : ''; ?></span>