hdbrandon Posted June 29, 2011 Share Posted June 29, 2011 I'm pulling text from a database to use as the alt= for a photo gallery. Also, each picture has a longer description. If the description does not exist (ie table field is empty), the alt= text should act as both. Simple enough but its not working? $fname=mysql_result($result,$i,'filename'); $username=mysql_result($result,$i,'userID'); $store=mysql_result($result,$i,'store'); $date=mysql_result($result,$i,'date'); $altText=mysql_result($result,$i,'alt'); $descText=mysql_result($result,$i,'descText'); //if no photo story, use altText as such. if(($descText=='') || ($descText==' ') || ($descText == null)){ $descText == $altText; } echo" <td valign='top'> <a href='$url/gallery/image.php/image.jpg?width=800&height=800&image=$url/gallery/$fname' rel='lightbox[pictures]' title='$descText'> <img src='$url/gallery/image.php/image.jpg?width=75&height=75&image=$url/gallery/$fname' alt='$altText' border='0' /> </a> </td> "; I've tried both ways- $altText==$descText and $descText ==$altText. Shouldnt it be as above? Website is still in production, but see http://qa.theapron.com for an idea of what I mean. This is being used on conjunction with the lightbox script. Link to comment https://forums.phpfreaks.com/topic/240725-variable-assignment-problem/ Share on other sites More sharing options...
fugix Posted June 29, 2011 Share Posted June 29, 2011 what exactly is your problem? and you need to use = not == to assign a value to a variable. if(($descText=='') || ($descText==' ') || ($descText == null)){ $descText = $altText; } Link to comment https://forums.phpfreaks.com/topic/240725-variable-assignment-problem/#findComment-1236451 Share on other sites More sharing options...
KevinM1 Posted June 29, 2011 Share Posted June 29, 2011 You want: if(($descText == '') || ($descText == ' ') || ($descText == null)){ $descText = $altText; } Note only one '=' for assignment, '==' for equals comparison. You should also look into empty. Link to comment https://forums.phpfreaks.com/topic/240725-variable-assignment-problem/#findComment-1236454 Share on other sites More sharing options...
hdbrandon Posted June 29, 2011 Author Share Posted June 29, 2011 Sorry, I wasnt clear. And, @nightslyr-thanks I took your advice and am using empty. The db has a short description(use for the alt= hover) and longer description for when the picture is expanded(lightbox). Never will both fields be empty. The problem: if their is a short description, use it as the alt=. If their is a longer description, use that when picture is expanded. If one of the two fields are empty, use the other to take its place. So, for instance, picture #27-the last one. The database is: altText: cowboy boot descTest:Have you heard of people of home depot? $date=mysql_result($result,$i,'date'); $altText=mysql_result($result,$i,'alt'); $descText=mysql_result($result,$i,'descText'); //if no photo story, use altText as such. if(empty($descText)){ $descText = $altText; } else if(empty($altText)){ $altText = $descText; } else{ } It seems to be working now. Thanks. I think my cookies were screwing me up too. Link to comment https://forums.phpfreaks.com/topic/240725-variable-assignment-problem/#findComment-1236473 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.