SETTING UP IF/THEN CONDITIONS - Aug 2nd, 2010


This time it was me that was in need of some guidance and Dave Edis from Interactive Tools was able to help.

Here was my situation:
I had set up a multi record section editor and included a pull down list field with a list of categories. IE: “book,
CD, Magazine, etc.

(BTW, the difference between a simple pull down list and a multi value pull down list is that in a multi value pull down
if you hold the CTL key you can select more than one value)

Here’s what I was trying to do:

If the group_code of the particular record is “book” then I wanted to display field “A”, if it’s “CD”
I’d like to display field “B”, if it’s “magazine” I’d like to display field “C”, and if it’s none of
those I’d like to display field “D”.

The task is pretty straightforward once you know the correct format to use.

If you’re using it on multi record a list page:


<?PHP foreach ($pub_category_listRecords as $record): ?>
<?PHP if ($record['group_code'] == "book"): ?>
<?PHP echo $record['fieldA'] ?>
<?PHP elseif ($record['group_code'] == "CD"): ?>
<?PHP echo $record['fieldB'] ?>
<?PHP elseif ($record['group_code'] == "Magazine"): ?>
<?PHP echo $record['fieldC'] ?>
<?PHP else: ?>
<?PHP echo $record['fieldD'] ?>
Sorry, couldn't find a match for '<?PHP echo $record['group_code'] ?>'
<?PHP endif ?>
<?PHP endforeach; ?>



And if it’s on a single page or a detail page:



<?PHP if ($pub_category_listRecord['group_code'] == "book"): ?>
<?PHP echo $pub_category_listRecord['fieldA'] ?>
<?PHP elseif ($pub_category_listRecord['group_code'] == "CD"): ?>
<?PHP echo $pub_category_listRecord['fieldB'] ?>
<?PHP elseif ($pub_category_listRecord['group_code'] == "Magazine"): ?>
<?PHP echo $pub_category_listRecord['fieldC'] ?>
<?PHP else: ?>
<?PHP echo $pub_category_listRecord['fieldD'] ?>
Sorry, couldn't find a match for '<?PHP echo $pub_category_listRecord['group_code'] ?>'
<?PHP endif ?>



You can use this to display anything that you want to, in another situation I’m using it to display different
thumbnail groups for different group codes. Just replace the <?PHP echo $record['fieldn'] ?> codes with the code that
will display what you want to.

There’s much more on understanding and using if statements later in the Cookbook.



The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service