Category filter by another table

5 posts by 2 authors in: Forums > CMS Builder
Last Post: July 8, 2011   (RSS)

Re: [ht1080z] Category filter by another table

By Jason - July 7, 2011

Hi,

I took a look at your code. If I understand it correctly, if your page has returned products, you want to display them. If not, you want to display the records from "$cat1Records". I did notice this in your code:

<?php if ($cat1Record['_isSelected'] || $cat1Record['_isDescendantSelected']): ?>
<a href="<?php echo $cat1Record['_link'] ?>"><?php if($cat1Record['name']) echo $cat1Record['name']; else echo $cat1Record['name']; ?></a>
<?php else: ?>
<a href="<?php echo $cat1Record['_link'] ?>"><?php if($cat1Record['name']) echo $cat1Record['name']; else echo $cat1Record['name']; ?></a>
<?php endif; ?>


In this code, you are outputting a category link regardless of whether that record is part of the selected category branch or not. If you want to only output categories if they're selected or their children are selected, try this:

<?php if ($cat1Record['_isSelected'] || $cat1Record['_isDescendantSelected']): ?>
<a href="<?php echo $cat1Record['_link'] ?>"><?php if($cat1Record['name']) echo $cat1Record['name']; else echo $cat1Record['name']; ?></a>
<?php endif; ?>


Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Category filter by another table

By ht1080z - July 7, 2011 - edited: July 8, 2011

Hi Jason,

Thank you for your reply!

I try filter only the first level of the selected branch. See code below until now how. (the parentnum is not working.)

<?php foreach ($cat1Records as $cat1Record): ?>
<?php if ($cat1Record['_isSelected'] || $cat1Record['_isAncestorSelected'] && ($cat1Record['parentNum'] = $selected1Category['num'])): ?>
<a href="<?php echo $cat1Record['_link'] ?>"><?php echo $cat1Record['name']; ?></a>
<?php echo $cat1Record['content'] ?><br/>
<?php endif; ?>
<?php endforeach; ?>


Any suggestion on this?
Thanks again!

Re: [ht1080z] Category filter by another table

By Jason - July 8, 2011

Hi,

What's happening here is your using "=" which is an assignment operator instead of "==" which is for comparison.

Try this:

<?php foreach ($cat1Records as $cat1Record): ?>
<?php if (($cat1Record['_isSelected'] || $cat1Record['_isAncestorSelected'] ) && ($cat1Record['parentNum'] == $selected1Category['num'])): ?>
<a href="<?php echo $cat1Record['_link'] ?>"><?php echo $cat1Record['name']; ?></a>
<?php echo $cat1Record['content'] ?><br/>
<?php endif; ?>
<?php endforeach; ?>


This is actually a very common mistake (I make it all the time!)

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Category filter by another table

By ht1080z - July 8, 2011

Jason!

Thank for your support on this again! [:)]