AdRock Posted September 6, 2006 Share Posted September 6, 2006 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 https://forums.phpfreaks.com/topic/19947-storing-image-alt-tags-in-database-resolved/ Share on other sites More sharing options...
majocmatt Posted September 6, 2006 Share Posted September 6, 2006 alt=".[color=red]addslahes([/color]$code['alternate'][color=red])[/color]." Link to comment https://forums.phpfreaks.com/topic/19947-storing-image-alt-tags-in-database-resolved/#findComment-87405 Share on other sites More sharing options...
AdRock Posted September 6, 2006 Author Share Posted September 6, 2006 Doesn't work....still only displays the first word Link to comment https://forums.phpfreaks.com/topic/19947-storing-image-alt-tags-in-database-resolved/#findComment-87410 Share on other sites More sharing options...
majocmatt Posted September 6, 2006 Share Posted September 6, 2006 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? Link to comment https://forums.phpfreaks.com/topic/19947-storing-image-alt-tags-in-database-resolved/#findComment-87412 Share on other sites More sharing options...
AdRock Posted September 6, 2006 Author Share Posted September 6, 2006 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 wordI tested a different word on another image and the same thing happens.....only the first word Link to comment https://forums.phpfreaks.com/topic/19947-storing-image-alt-tags-in-database-resolved/#findComment-87414 Share on other sites More sharing options...
AdRock Posted September 6, 2006 Author Share Posted September 6, 2006 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 Link to comment https://forums.phpfreaks.com/topic/19947-storing-image-alt-tags-in-database-resolved/#findComment-87416 Share on other sites More sharing options...
majocmatt Posted September 6, 2006 Share Posted September 6, 2006 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? Link to comment https://forums.phpfreaks.com/topic/19947-storing-image-alt-tags-in-database-resolved/#findComment-87420 Share on other sites More sharing options...
MarioRossi Posted September 6, 2006 Share Posted September 6, 2006 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 thisecho "<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 ALTHope that works for you. Link to comment https://forums.phpfreaks.com/topic/19947-storing-image-alt-tags-in-database-resolved/#findComment-87441 Share on other sites More sharing options...
AdRock Posted September 7, 2006 Author Share Posted September 7, 2006 I did try using single quotes but obviously put it in the wrong place and it made the images disappearThanks MarioRossi, it works.......woohoo Link to comment https://forums.phpfreaks.com/topic/19947-storing-image-alt-tags-in-database-resolved/#findComment-87660 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.