Complex If Statements

7 posts by 2 authors in: Forums > CMS Builder
Last Post: July 3, 2010   (RSS)

By jtedescojam - July 2, 2010

I have CMS Builder loaded with a single section editor that holds all of the clients furniture products. Each product is categorized using check marks... for example.. king size canopy, chair, fireplace, table, etc... so that the client can check off multiple categories.

I am developing a single viewer url that needs to call up specific categories, and display products ONLY if it's checked off and if it's in the dining room room_type. The check box code is what's confusing me.. please email me at your earliest convenience what I can use for this.

Quick example...

Dining Room Products Page showing all products listed with room_type:Dining Room:
If a dining room room_type item is checked as a fireplace - show it
If a dining room room_type item is checked as a table - show it
If a dining room room_type item is checked as a chair - show it
etc..

thank you!
John Tedesco

Creative Director



JAM Graphics

Re: Complex If Statements

By jtedescojam - July 3, 2010

Thanks for posting the generic 'if' statements instructions, It'll certainly help in the future... unfortunately this hasn't helped my issue. I have a specific page calling up all products with the room_type 'dining rooms' using the following header code:
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php

require_once "\\\\frigga/home/users/web/b2870/as.shopfurniture/admin/lib/viewer_functions.php";

list($collections_itemsRecords, $collections_itemsMetaData) = getRecords(array(
'tableName' => 'collections_items',
'allowSearch' => '0',
'where' => "room_type LIKE '%\tDining Room\t%'",
));
?>

Now, I want to display only products on this page that has the category "fireplaces" checked off... this is what's traditional, and I think this would work if it was a pull down list... but it has to be check marks...
<?php foreach ($collections_itemsRecords as $record): ?>
<?php if ($record['category'] == 'fireplaces'): ?>
<div id="product-listing">
<?php if ($record['images']): ?>
<a href="<?php echo $record['_link'] ?>"><?php foreach ($record['images'] as $upload): ?><img src="<?php echo $upload['thumbUrlPath'] ?>" alt="<?php echo $record['collection'] ?>" class="thumbnail" /><?php break ?><?php endforeach ?></a>
<?php else: ?><a href="<?php echo $record['_link'] ?>"><img src="../images/img-notavailable-75x100.jpg" class="thumbnail" /></a><?php endif ?>
<h2><?php echo $record['collection'] ?></h2>
<p><?php echo $record['price'] ?></p>
</div>
<h2>
<?php endif ?>
<?php endforeach ?>

But I think because this is a checkbox sequence, it's going to be a bit more complicated. I have 1 record that has both dining rooms and fireplaces checked off.

thanks again for the assist.
John Tedesco

Creative Director



JAM Graphics

Re: [jtedescojam] Complex If Statements

By gkornbluth - July 3, 2010

You might try strpos instead of just an if

In addition to the note in the recipe, here are 2 posts that might help.

http://www.interactivetools.com/iforum/gforum.cgi?post=76002

http://www.interactivetools.com/iforum/gforum.cgi?post=77647

Best,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: Complex If Statements

By jtedescojam - July 3, 2010

Yeah that'll do it.. thank you! I'm going to have to buy the cookbook now! Thanks for the help.

Not sure you have the time.. not sure I have the time.. but if you're up for a challenge... I'd like to be able to do this without having to duplicate the following block of code for every single category...

<?php foreach ($collections_itemsRecords as $record): ?>
<?php if (strpos($record['category'], 'Chests')): ?>
<h3>Chests</h3><?php break ?><?php endif ?><?php endforeach ?>
<?php foreach ($collections_itemsRecords as $record): ?>
<?php if (strpos($record['category'], 'Chests')): ?>
<div id="product-listing">
<?php if ($record['images']): ?>
<a href="<?php echo $record['_link'] ?>"><?php foreach ($record['images'] as $upload): ?><img src="<?php echo $upload['thumbUrlPath'] ?>" alt="<?php echo $record['collection'] ?>" class="thumbnail" /><?php break ?><?php endforeach ?></a>
<?php else: ?><a href="<?php echo $record['_link'] ?>"><img src="../images/img-notavailable-75x100.jpg" class="thumbnail" /></a><?php endif ?>
<h2><?php echo $record['item_name'] ?></h2>
<p><?php echo $record['price'] ?></p>
</div>
<?php endif ?>
<?php endforeach ?>
<div style="clear:both"></div>


Let me know if you know a way.
John Tedesco

Creative Director



JAM Graphics

Re: [jtedescojam] Complex If Statements

By gkornbluth - July 3, 2010

Hi jtedescojam,

I like clean code too, but these kinds of details usually go into my "Some day..." pile.

I'm sure that there are some more elegant approaches to this issue, but a big piece of me says, "If it ain't broke..."

So...

Glad it's working for you.

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Complex If Statements

By jtedescojam - July 3, 2010

Thanks again
John Tedesco

Creative Director



JAM Graphics