Jump to content


Photo

not to display empty fields


  • Please log in to reply
7 replies to this topic

#1 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 14 July 2006 - 10:57 PM

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

$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>';

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

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 14 July 2006 - 11:22 PM

if(! $events_allowed['performersr' ]==0) {
}else{
echo $events_allowed ['performersr'] ;
}

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 14 July 2006 - 11:30 PM

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

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#4 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 15 July 2006 - 12:47 AM

thanks guys but I already knew that, was just hoping that there was a cleaner way to do this.

$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>';

btw for those lines to work it has to be != '' and not !=0

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 15 July 2006 - 12:50 AM

You could use a large array but i think looks good.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 15 July 2006 - 12:53 AM

and to make ur coding look nicer use the [tab] button its located above the caps lock

#7 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 15 July 2006 - 01:47 AM

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.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#8 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 15 July 2006 - 01:53 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users