jonesypeter Posted May 1, 2013 Share Posted May 1, 2013 Hello, I'm trying to add an alt tag to an image I am retrieving from a MySQL database but I am really struggling. The image is displayed with: echo "<td rowspan=3><img src=\"".$row['image_1']."\" > </td>"; What do I add include: alt="some_text" Many thanks Peter Jones Quote Link to comment Share on other sites More sharing options...
lemmin Posted May 1, 2013 Share Posted May 1, 2013 Since the image generation is dynamic, you have to have information about that image. Do you have the image's description in the database too? If not, you can just set the alt tag to be the filename of the image: echo "<td rowspan=3><img alt=\"".$row['image_1']."\" src=\"".$row['image_1']."\" > </td>"; Quote Link to comment Share on other sites More sharing options...
jonesypeter Posted May 1, 2013 Author Share Posted May 1, 2013 Many thanks for the reply. I have the field 'title' I can use. So I have done: echo "<td rowspan=3><img alt=\"".$row['title']."\" src=\"".$row['image_1']."\" > </td>"; The rendered HTML code comes through as: <td rowspan=3><img alt="Firelord" src="/images/spectrum/loading/Firelord.gif" > http://retro.getfreehosting.co.uk/retroseek.php?pid=1 The trouble is that the alt tag title is not appearing when I hover over the image Thanks Peter Quote Link to comment Share on other sites More sharing options...
DavidAM Posted May 1, 2013 Share Posted May 1, 2013 ALT is used to display text INSTEAD of the image if the user has images turned off, or they are using a non-graphical browser. Some browsers display the ALT value in a "tooltip" just because they want to. However, you can use the TITLE attribute, which (I believe) most browsers will display as a "tooltip" on hover. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.