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

I am making an online portfolio. I want to have links to previews of pages. I made 3 textfields as each project would have at most 3 links to preview pages.

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

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: [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