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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.