link change based on field contents

5 posts by 2 authors in: Forums > CMS Builder
Last Post: November 15, 2010   (RSS)

Re: [Oakweb] link change based on field contents

By zip222 - November 14, 2010

This should do it...

<?php foreach ($adventure_and_sportRecords as $record): ?>
<div class="itemPreview">
<?php if ($record['website']): ?>
<h1><a href="<?php echo $record['website'] ?>"><?php echo $record['title'] ?></a></h1>
<?php echo $record['preview_description'] ?>
<strong><a href="<?php echo $record['website'] ?>">Find out more &raquo;</a></strong>
<?php else ?>
<h1><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a></h1>
<?php echo $record['preview_description'] ?>
<strong><a href="<?php echo $record['_link'] ?>">Find out more &raquo;</a></strong>
<?php endif ?>
</div>
<?php endforeach ?>

Re: [zip222] link change based on field contents

By Oakweb - November 15, 2010

Thank you

Unfortunately this has thrown up the error

Parse error: syntax error, unexpected ';', expecting ':' in /home/asksam/3P216Y7H/htdocs/adventure_and_sport.php on line 88

Line 88 refers to <?php else ?>

Re: [zip222] link change based on field contents

By Oakweb - November 15, 2010

Hi - I've cracked it.

Should have been

<?php foreach ($adventure_and_sportRecords as $record): ?>
<div class="itemPreview">
<?php if ($record['website']): ?>
<h1><a href="<?php echo $record['website'] ?>"><?php echo $record['title'] ?></a></h1>
<?php echo $record['preview_description'] ?>
<strong><a href="<?php echo $record['website'] ?>">Find out more &raquo;</a></strong>
<?php elseif ($record['_link']): ?>
<h1><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a></h1>
<?php echo $record['preview_description'] ?>
<strong><a href="<?php echo $record['_link'] ?>">Find out more &raquo;</a></strong>
<?php endif ?>
</div>
<?php endforeach ?>

It was the <?php elseif ($record['_link']): ?> bit.

Thanks for your help though as I wouldn't have got that far without your start.

Re: [Oakweb] link change based on field contents

By zip222 - November 15, 2010

Actually, all you really need to add to the "else" line is a colon...

<?php else: ?>