Jump to content


Photo

Storing image alt tags in database [RESOLVED]


  • Please log in to reply
8 replies to this topic

#1 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 06 September 2006 - 09:18 PM

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

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 the

Any ideas what would cause this?

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

If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#2 majocmatt

majocmatt
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 06 September 2006 - 09:20 PM

alt=".addslahes($code['alternate'])."

#3 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 06 September 2006 - 09:28 PM

Doesn't work....still only displays the first word
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#4 majocmatt

majocmatt
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 06 September 2006 - 09:31 PM

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?

#5 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 06 September 2006 - 09:34 PM

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
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#6 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 06 September 2006 - 09:40 PM

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
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#7 majocmatt

majocmatt
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 06 September 2006 - 09:57 PM

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?

#8 MarioRossi

MarioRossi
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 06 September 2006 - 10:43 PM

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.

#9 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 07 September 2006 - 11:38 AM

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
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users