Words into Image Alt tags

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
NotOnUrNelly
Forum Commoner
Posts: 61
Joined: Wed Mar 24, 2004 4:45 pm

Words into Image Alt tags

Post by NotOnUrNelly »

Hi All,

Just wondering whether this can be done.

I have a text field from a database. I need this to be displayed in a table, but the text is varying lengths and makes my tables look unsightly. The text is not essential and an option I am considering is having a small image appear in the last column of my table if the field has a value.

When the image is hovered I want the text to be displayed in the alt tag.

I have used the following code to try to achieve this

Code: Select all

<?php 
		   if ($Issues){ ?>
		<img src="images/title.jpg" width="10" height="10" alt = <?php echo $Issues;?>>
		<?php
		  }
		  ?>
This code only produces the first word when the image is hovered.

Many Thanks
Jamie
User avatar
themurph
Forum Commoner
Posts: 76
Joined: Wed Apr 19, 2006 1:56 pm
Contact:

Post by themurph »

Add double quotes for the alt= attribute

Something like:

Code: Select all

<?php
if ($Issues) {
     echo "<img src=\"images/title.jpg\" width=\"10\" height=\"10\" alt=\"$Issues\">\n";
}
?>
NotOnUrNelly
Forum Commoner
Posts: 61
Joined: Wed Mar 24, 2004 4:45 pm

Post by NotOnUrNelly »

Many Thanks for that it worked a treat.

Jamie
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

This applies to any HTML tag attribute that accepts spaced strings in them (like the value attribute of the <input> tag). In fact, to be compliant with XHTML or STRICT HTML standard, all of your HTML element attributes must be wrapped in double quotes.
Post Reply