Jump to content

Archived

This topic is now archived and is closed to further replies.

AdRock

Storing image alt tags in database [RESOLVED]

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]

Share this post


Link to post
Share on other sites
It seems like your problem is apostraphes in your captions (alts), are you sure its printing just the first word? Or is it printing all the letters up until an apostraphe or slash?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
I just echoed what was in the alternate field (alt tag) and what was echoed is what should be displayed in the image alt tag

Share this post


Link to post
Share on other sites
Yea I've had that problem before displaying alt's, I'm just trying to think how I fixed it because I can't find the files.

did you try stripslashes too?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
I did try using single quotes but obviously put it in the wrong place and it made the images disappear
Thanks MarioRossi, it works.......woohoo

Share this post


Link to post
Share on other sites

×

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.