The tiny piece of code below means, if the alias of a person is unavailable in the database, echo the person's name. Otherwise, echo the alias. echo (empty($row['alias']) ? $row['name'] : $row['alias']); PHP: If the alias is going to be echoed, I want it to be echoed in bold, red font, so I used a span tag and added a CSS class: echo (empty($row['alias']) ? $row['name'] : "Alias is: <span class=\"boldred\">" . $row['alias']) . "</span>"; PHP: It worked. However, when it echoes the name and not the alias, my HTML doesn't validate, because it also echoes the closing span tag. In other words, it either echoes this Alias is: Alias or this Name</span> (of course, you can't see the span tag). Anyone know how I can fix this?
You have your closing bracket for echo in the wrong spot. It should be echo (empty($row['alias']) ? $row['name'] : "Alias is: <span class=\"boldred\">" . $row['alias'] . "</span>"); PHP: