Making a field only appear if it has data

4 posts by 3 authors in: Forums > CMS Builder
Last Post: June 9, 2008   (RSS)

Re: [AgentBristow] Making a field only appear if it has data

By Kenny - June 8, 2008

For each link you could use:

<?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

Cool, thanks that works well. I'm using the below code >

<?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

Hi AgentBristow,

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?
Dave Edis - Senior Developer
interactivetools.com