Jump to content

[SOLVED] Can't think of appropriate subject heading! Confused!


Fluoresce

Recommended Posts

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']);

 

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>";

 

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?

Carefully look at your parentheses, then you should be able to work out why.

 

Ah . . .

 

Thanks, Jamesnes! I now see the problem. It should be like this:

 

echo (empty($row['alias']) ? $row['name'] : "Alias is: <span class=\"boldred\">" . $row['alias'] . "</span>");

 

I appreciate it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.