4 posts by 2 authors in: Forums > CMS Builder
Last Post: December 10, 2012   (RSS)

By sidcam - December 10, 2012

I'm displaying this field in a prominent position on a record page:

<?php echo htmlencode($listing_resiRecord['square_footage']) ?>

But half the time the field is blank and I'd really love it to display a standard answer like "N/A" or "Not Available" instead of just running into the next field title.

Is there a way to insert an if/then or if/else into that statement?

Thanks, Sid

Re: [sidcam] Display Alternative Results when Field is Blank

Hi Sid,

Something like this should work:


<?php echo (@$listing_resiRecord['square_footage'])? htmlencode($listing_resiRecord['square_footage']) : 'N/A' ; ?>


So if $listing_resiRecord['square_footage'] exists and contains content then it will be echoed, else N/A will be echoed instead.

Thanks!
Greg Thomas















PHP Programmer - interactivetools.com

Re: [greg] Display Alternative Results when Field is Blank

By sidcam - December 10, 2012 - edited: December 10, 2012

Awesome!

Kind of along this same line. Our postal codes in the US are six digits but can have an extra (optional) 4 digits behind them separated by a dash (i.e. 123456 or 123456-1234). I get this data in two separate fields. The main postal field is always filled out; The optional "extra four" field is only filled out about half the time.

My problem is the dash because it only needs to be there when there's data in the second field. I was looking at what you just did to see if it would work for this, but can't quite figure out how to insert a '-' in front of the field's data when the field is available.

<?php echo (@$listing_resiRecord['postal_extrafour'])? htmlencode($listing_resiRecord['postal_extrafour']) : '' ; ?>

Thanks, Sid