How to skip empty fields

7 posts by 4 authors in: Forums > CMS Builder
Last Post: March 17, 2011   (RSS)

Re: [furcat] How to skip empty fields

By Dave - October 1, 2009

Hi furcat, welcome to the CMS Builder forum! :)

You can use a PHP "if" statement for that. Try this:

<?php if ($record['phone']): ?>
Phone: <?php echo $record['phone'] ?>
<?php endif ?>


Just replace $record['phone'] with whatever your variable is called and put the html that you want displayed (or not) inside the if/endif tags.

Hope that helps! Let me know how it goes.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] How to skip empty fields

By furcat - October 1, 2009

Dave - thank you very much. That's what I needed. It works just fine.

Re: [Dave] How to skip empty fields

By degreesnorth - March 16, 2011

Hi Dave

I have a question similar to this but can't get this code to work. What I am trying to do is that if product A has a link, then display an image (moreinfo.jpg) to indicate there is a link and display the (moreinfo.jpg) image which makes this link open in a new browser window. If there is no link, then don't display the image (as there is no link). Is there a way to do this? Basically, so it skips that line and goes on to the next product.

Thanks

Re: [degreesnorth] How to skip empty fields

By Dave - March 16, 2011

Hi degreesnorth,

Sure, no problem. What is the link field called? Eg: $record['product_link']?
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] How to skip empty fields

By degreesnorth - March 16, 2011

Hi Dave
There are actually 2 fields
- product_2
- product_2_info_link
(and then product_3 and product_3_info_link), etc.
If there is no product 3, 4 and 5, then basically I want to skip displaying this information. I would have set them up as individual records (ie, the products as a multiple record list), there are too many other variables on this page with categories, subcategories, etc and it would get too confusing with too many IF > THEN statements.
Thanks
Carole

Re: [degreesnorth] How to skip empty fields

By Jason - March 17, 2011

Hi Carole,

You can try something like this:

<?php if ($record['product_2_info_link']): ?>
// output image
<?php endif ?>

<?php if ($record['product_3_info_link']): ?>
// output image
<?php endif ?>


Give this a try and let us know how that works for you. If you run into any problems, let us know and attach the .php file you're working with so we can take a look at what's happening.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/