Jump to content

Storing image alt tags in database [RESOLVED]


AdRock

Recommended Posts

I have stored my images in the database by having their name such as [b]something.jpg[/b] in a name field and in the alt field I have the alt tag such as [b]this is a picture of something[/b]

When i come to display the picture I get the picture displayed ok but the alt tag has only the first word shown so in my example it would display [b]the[/b]

Any ideas what would cause this?

[code]echo "<p class='style2'><img src=/images/".$code['photo']." alt=".$code['alternate'].">".nl2br($code['content'])."</p>";[/code]
In my caption (alts) I have about 4 words whith no apostrophes and slashes or anything.

I checked in phpMyAdmin and I can see all the alts i'm trying to echo all have the same first word

I tested a different word on another image and the same thing happens.....only the first word
Your problem lies not within the PHP but the html you are outputting. If you view the source of the page you will see what I mean.

what you are outputting is this

<img src=/images/yourimageurl.gif alt=Your alt text>

The spaces therfore are not associated with the alt attribute.

Try this

echo "<p class='style2'><img src='/images/".$code['photo']."' alt='".$code['alternate']."'>".nl2br($code['content'])."</p>";

I have added single quotes to contain your values for SRC and ALT

Hope that works for you.

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.