IF/THEN Statement (PHP) for custom fields

3 posts by 2 authors in: Forums > CMS Builder
Last Post: December 22, 2007   (RSS)

Re: [rasbro] IF/THEN Statement (PHP) for custom fields

By Dave - December 22, 2007

Looks pretty close, generally you can just specify "" to match an empty fields. So you could write it like this:

<?php if ($record['sale_price'] == ""): ?>
Price: $<?php echo $record['price'] ?><br/>
<?php else: ?>
Price: $<?php echo $record['price'] ?><br/>
Sale Price: $<?php echo $record['sale_price'] ?><br/>
<?php endif ?>


or another way (maybe simpler) would be like this:

Price: $<?php echo $record['price'] ?><br/>

<?php if ($record['sale_price'] != ""): ?>
Sale Price: $<?php echo $record['sale_price'] ?><br/>
<?php endif ?>


With != to mean "sale price is not empty". Hope that helps! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] IF/THEN Statement (PHP) for custom fields

By rasbro - December 22, 2007

It works great Dave, thank you!