How to skip empty fields
7 posts by 4 authors in: Forums > CMS Builder
Last Post: March 17, 2011 (RSS)
By furcat - October 1, 2009
So, I am at the point of needing some more information. One question that I have is with pages that have multiple rows per page. I have a contact us page where there will be information such as name, title, address, phone, etc. However, not each entry will have everything, and I don't want it to display "Phone," for instance, without anything next to it on the web page.
Here's the page I am working with:
http://ecsxtal.rossini.com/contact_us.php
So, what I'm looking for is for the field and field label to display if there is an entry, but, don't want it to display if it is empty.
Thanks in advance.
Re: [furcat] How to skip empty fields
By Dave - October 1, 2009
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.
interactivetools.com
Re: [Dave] How to skip empty fields
By furcat - October 1, 2009
Re: [Dave] How to skip empty fields
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
Sure, no problem. What is the link field called? Eg: $record['product_link']?
interactivetools.com
Re: [Dave] How to skip empty fields
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
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/