onMouseOver with PHP = how?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

onMouseOver with PHP = how?

Post by simonmlewis »

Code: Select all

 if ($row->status == "on hold") { echo "
      <tr bgcolor='#FFCF00' onMouseOver=\"this.bgColor='#FFCF00';\" onMouseOut=\"this.bgColor='#FFCF00';\">
      "; }
      
      elseif ($row->status == NULL) { echo "
      <tr bgcolor='#ffffff' onMouseOver=\"this.bgColor='#E7E7E7';\" onMouseOut=\"this.bgColor='#FFFFFF';\">
      "; }
This products the highlighted #FFCF00 and keeps it highlighted when you hover over. But none of the other fields go grey.
This on it's own....

Code: Select all

<tr bgcolor='#ffffff' onMouseOver=\"this.bgColor='#E7E7E7';\" onMouseOut=\"this.bgColor='#FFFFFF';\">
.... works.

So what's wrong with the If statement? I am sure it is something to do with the " and ' (from a previous post about this, I could understand), but it appears fine to me.

It's meant to highlight the row light grey on hover(mouseover), but for those 'on hold' it should stay orange.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: onMouseOver with PHP = how?

Post by cpetercarter »

The problem may lie in your "elseif" statement. Are you sure that the right condition is $row->status == NULL and not, for example, $row->status == "" ?

Code: Select all

if (empty($row->status))
would catch $row->status == NULL and $row->status == false and $row->status == "".
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: onMouseOver with PHP = how?

Post by simonmlewis »

Yes I am, as the field only has content or NULL.

I've just sussed it. Trying ....
} else {
rather than
} elseif {

works!!

Code: Select all

            if ($row->status == "on hold") { echo "
      <tr bgcolor='#FFCF00' onMouseOver=\"this.bgColor='#FFCF00';\" onMouseOut=\"this.bgColor='#FFCF00';\">
      "; }
      
      else { echo "
      <tr bgcolor='#FFFFFF' onMouseOver=\"this.bgColor='#E7E7E7';\" onMouseOut=\"this.bgColor='#FFFFFF';\">
      "; }
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: onMouseOver with PHP = how?

Post by cpetercarter »

I am glad you have sorted this problem. However, it cannot be the case that $row->status is either "on hold" or NULL, because if that were so your original code would have worked. Perhaps a form submission, or some other action in your script, has given rows which are not "on hold" a value, perhaps "" or 'false'.
Post Reply