Jump to content

Archived

This topic is now archived and is closed to further replies.

digitalgod

not to display empty fields

Recommended Posts

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

Share this post


Link to post
Share on other sites
if(! $events_allowed['performersr' ]==0) {
}else{
echo $events_allowed ['performersr'] ;
}

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
and to make ur coding look nicer use the [tab] button its located above the caps lock

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.