Making a field only appear if it has data
4 posts by 3 authors in: Forums > CMS Builder
Last Post: June 9, 2008 (RSS)
By _kate_ - June 8, 2008
Some projects will have no links, some 1 others 3 etc. How can I get this information to only display when it has data in that field? I am trying to get a display something like the below >
View: <a href="<?php echo $record['store'] ?>" target="_blank">Store Front</a>, <a href="<?php echo $record['auction'] ?>" target="_blank">Auction Template</a>
Re: [AgentBristow] Making a field only appear if it has data
By Kenny - June 8, 2008
<?php if ($record['store']): ?><a href="<?php echo $record['store'] ?>" target="_blank">Store Front</a><?php endif ?>
<?php if ($record['auction']): ?><a href="<?php echo $record['auction'] ?>" target="_blank">Auction Template</a><?php endif ?>
Re: [sagentic] Making a field only appear if it has data
By _kate_ - June 8, 2008
<?php if ($record['store']): ?>View: <?php endif ?>
<?php if ($record['store']): ?><a href="<?php echo $record['store'] ?>" target="_blank">Store Front</a><?php endif ?>
<?php if ($record['auction']): ?><a href="<?php echo $record['auction'] ?>" target="_blank">Auction Template</a><?php endif ?>
Sometimes I may only have the Auction Template link, and with the above code in this form the word "View" wouldn't display if there was only an auction link. How can I edit the code so that it shows "View" if the record is "store" OR "auction"?
Also, if there is more than one link showing, is there anyway to get it to display a comma after each record (except the last one)?
Thanks :)
Re: [AgentBristow] Making a field only appear if it has data
By Dave - June 9, 2008
You can use " or " like this to test on more than one condition:
<?php if ($record['store'] or $record['auction']): ?>
View:
<?php endif ?>
And if you only had two links, you could use the same if statement to print a comma in the middle if both were defined. Will that work for you?
interactivetools.com