digitalgod Posted July 14, 2006 Share Posted July 14, 2006 hey guys,I have a page that displays events that are stored in the db but sometimes some of the fields are empty and when that happens I don't want it to display that line.this is what I mean[code]$events_allrow = mysql_fetch_array($display_result); echo '<div style="margin-left:10px; margin-top:10px "><img src="images/square1.jpg" align="absmiddle" style="margin-right:5px "><strong class="light_gray">'.$events_allrow['name'].'</strong></div> <div style="margin-left:9px; margin-top:7px; width:354px "><div style="position:relative; left:0; top:0; "><img src="../img/events/'.$events_allrow['name'].'/thumbnails/'.$events_allrow['flyer1'].'" align="left" style="margin-right:13px "></div> <div>Where: <strong>'.$events_allrow['club'].'<br /></strong> When: <strong>'.$events_allrow['date'].'<br /></strong></div> Time: <strong>'.$events_allrow['time'].'<br /></strong></div> Performers: <strong>'.$events_allrow['performers'].'<br /></strong></div> DJ: <strong>'.$events_allrow['dj'].'<br /></strong></div> Promoter: <strong>'.$events_allrow['promoter'].'<br /></strong></div> Music: <strong>'.$events_allrow['music'].'<br /></strong></div> Cover Price: <strong>$'.$events_allrow['cover'].'<br /></strong></div> Dress code: <strong>'.$events_allrow['dress'].'<br /></strong></div> Notes: <strong>'.$events_allrow['notes'].'<br /></strong></div> Tickets: <strong>'.$events_allrow['tickets'].'<br /></strong></div> Guestlist: <strong>'.$events_allrow['guestlist'].'</strong></div> <div style="margin-top:7px " align="right"></div> </div> <div style="margin-top:7px " align="right"><a href="index.php?a=events&id=all" class="light_gray" style="text-decoration:none "><strong>view all</strong></a></div> </div> <div style="margin-left:8px; margin-top:10px; margin-right:8px; height:1px; background-image:url(images/dot.jpg) "><img src="images/spacer.gif"></div>';[/code]so for a specific event the 'performersr' field is empty what would be the easiest way to not make it display Performers:and that applies to most of the fields Quote Link to comment https://forums.phpfreaks.com/topic/14621-not-to-display-empty-fields/ Share on other sites More sharing options...
redarrow Posted July 14, 2006 Share Posted July 14, 2006 if(! $events_allowed['performersr' ]==0) {}else{echo $events_allowed ['performersr'] ;} Quote Link to comment https://forums.phpfreaks.com/topic/14621-not-to-display-empty-fields/#findComment-58170 Share on other sites More sharing options...
pixy Posted July 14, 2006 Share Posted July 14, 2006 Or just...if ($events_allowed['performers'] != 0) { echo $events_allowed['performers'];}Saves a line of code, and I dont think you're supposed to quote numbers... Quote Link to comment https://forums.phpfreaks.com/topic/14621-not-to-display-empty-fields/#findComment-58175 Share on other sites More sharing options...
digitalgod Posted July 15, 2006 Author Share Posted July 15, 2006 thanks guys but I already knew that, was just hoping that there was a cleaner way to do this.[code]$events_allrow = mysql_fetch_array($display_result); echo '<div style="margin-left:10px; margin-top:10px "><img src="images/square1.jpg" align="absmiddle" style="margin-right:5px "><strong class="light_gray">'.$events_allrow['name'].'</strong></div> <div style="margin-left:9px; margin-top:7px; width:354px "><div style="position:relative; left:0; top:0; "><img src="../img/events/'.$events_allrow['name'].'/thumbnails/'.$events_allrow['flyer1'].'" align="left" style="margin-right:13px "></div> <div>Where: <strong>'.$events_allrow['club'].'<br /></strong> When: <strong>'.$events_allrow['date'].'<br /></strong></div> Time: <strong>'.$events_allrow['time'].'<br /></strong></div>'; if ($events_allrow['performers'] != '') { echo 'Performers: <strong>'.$events_allrow['performers'].'<br /></strong></div>'; } if ($events_allrow['djs'] != '') { echo 'DJ: <strong>'.$events_allrow['dj'].'<br /></strong></div>'; } if ($events_allrow['promoter'] != '') { echo 'Promoter: <strong>'.$events_allrow['promoter'].'<br /></strong></div>'; } if ($events_allrow['music'] != '') { echo 'Music: <strong>'.$events_allrow['music'].'<br /></strong></div>'; } if ($events_allrow['cover'] != '') { echo 'Cover Price: <strong>$'.$events_allrow['cover'].'<br /></strong></div>'; } if ($events_allrow['dress'] != '') { echo 'Dress code: <strong>'.$events_allrow['dress'].'<br /></strong></div>'; } if ($events_allrow['notes'] != '') { echo 'Notes: <strong>'.$events_allrow['notes'].'<br /></strong></div>'; } if ($events_allrow['tickets'] != '') { echo 'Tickets: <strong>'.$events_allrow['tickets'].'<br /></strong></div>'; } if ($events_allrow['guestlist'] != '') { echo 'Guestlist: <strong>'.$events_allrow['guestlist'].'</strong></div>'; } echo '<div style="margin-top:7px " align="right"></div> </div> <div style="margin-top:7px " align="right"><a href="index.php?a=events&id=all" class="light_gray" style="text-decoration:none "><strong>view all</strong></a></div> </div> <div style="margin-left:8px; margin-top:10px; margin-right:8px; height:1px; background-image:url(images/dot.jpg) "><img src="images/spacer.gif"></div>';[/code]btw for those lines to work it has to be != '' and not !=0 Quote Link to comment https://forums.phpfreaks.com/topic/14621-not-to-display-empty-fields/#findComment-58214 Share on other sites More sharing options...
redarrow Posted July 15, 2006 Share Posted July 15, 2006 You could use a large array but i think looks good. Quote Link to comment https://forums.phpfreaks.com/topic/14621-not-to-display-empty-fields/#findComment-58216 Share on other sites More sharing options...
BillyBoB Posted July 15, 2006 Share Posted July 15, 2006 and to make ur coding look nicer use the [tab] button its located above the caps lock Quote Link to comment https://forums.phpfreaks.com/topic/14621-not-to-display-empty-fields/#findComment-58220 Share on other sites More sharing options...
ShogunWarrior Posted July 15, 2006 Share Posted July 15, 2006 I like the BSD style of coding, but some like K&R. Personally it's a bit hard to read for my liking.You could think about looping through the fields, which could cut out some code if you had the row names mapped to some display names. Quote Link to comment https://forums.phpfreaks.com/topic/14621-not-to-display-empty-fields/#findComment-58249 Share on other sites More sharing options...
digitalgod Posted July 15, 2006 Author Share Posted July 15, 2006 well in my editor everything is tabbed correctly but when I copy paste it into here the tabs aren't the same for some reason. Quote Link to comment https://forums.phpfreaks.com/topic/14621-not-to-display-empty-fields/#findComment-58252 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.