Hi guys,
I have a bit of code that displays an objects image, when you hover over it, it also shows the name of that object. What I would like, is when you hover over it for it to show the object Description instead, I am not sure what to put there and everything I have tried has failed. Any help would be appreciated.

function OBJECT_DisplayObject($P_Element)
{
$T_List = explode(",",$P_Element);
$T_Name = $P_Element;
$T_Description = SQL_ReadField("Objects",$P_Element,"Description");
$T_FullName = OBJECT_GiveDevelopedNameOfObject($P_Element);
echo '<div class="imageObject"><img src="ressources/images/objects/', $P_Element, '.jpg" width="150" height="150" hspace=0 vspace=0 title="', $P_Element, '"/></div>';
echo "<div style=\"width:160px;height:40;font-family:Garamond;\"><center><b>"
           .  $T_Name
           . "</b>";
if ($T_Name != $T_FullName)
  {
  echo "<br>" .  $T_FullName;
  }
echo "</div>";
}

Just give the title attribute a correct value to display the description. In your case line 7 would be:

echo '<div class="imageObject"><img src="ressources/images/objects/', $P_Element, '.jpg" width="150" height="150" hspace=0 vspace=0 title="', $T_Description, '"/></div>';

provided that the $T_Description variable contains the actual description.

Thank you for your reply. $T_Description does contain the item description, but it just wont work. Nothing comes up at all. I wasnt sure if there was something missing.

Member Avatar for diafol

This function looks a little odd.

Generally it's easier to echo the returned output of a function, rather than have echoes all over the place. Much easier to maintain that way.

The naming conventions you use are also a little awkward. As you have function scope, why not just give them simple varnames?

You create $T_List, but don't use it. Is there any point?

What exactly is $P_Element ?

At first I assumed it was an object, then I assumed it was a comma deliminated string. Then I thought it must be an array. Then I thought it must be a filepath.

Could you please show what P_Element is? Giving an example.

The code above works fine for me. Can you please post the generated HTML for your image (right click in the browser -> View page source).

Here is how it comes out

<div class="imageObject"><img src="ressources/images/objects/Shield.jpg" width="150" height="150" hspace=0 vspace=0 title="Shield"/></div><div style="width:160px;height:40;font-family:Garamond;"><center><b>Shield</b><br></div>

Hi Emma,
The resulting code looks fine, which browser are you using?

I would also caution against relative name paths for your images, you may not get the results you want.

Yes, the code is OK and should display the description when hovered over image (even if the image was not displayed due to incorrect path). Check out the css code for the title attribute and the imageObject class - even though it is unlikely that the css is set up the way it hides the title.

No, when you hover over the image it displays the image name. Changing it to description shows nothing at all. Everything else about this area of code works, including the differant images. Just cant seem to get this description to work.
Thanks for looking anyway guys.

Have you tried to echo the variable holding the description before put it into the title attribute?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.