Help separating products list

7 posts by 2 authors in: Forums > CMS Builder
Last Post: April 6, 2008   (RSS)

Re: [AgentBristow] Help separating products list

By Dave - April 5, 2008

Hi Kate, so glad to hear you're liking CMS Builder! :)

There's a few ways to do what you want. Let me know I understand you correctly. You want to list products on a page grouped by the category they're in? Is that right? If so, try this trick: Call the "foreach listrows" code multiple times and add an extra line to only display a certain "type" each time. Like this:

<h1>Type A Products</h1>
<?php foreach ($listRows as $record): ?>
<?php if ($record['table_type'] != "Type A") { continue; } ?>
Name: <?php echo $record['name'] ?><br/>
Title: <?php echo $record['title'] ?><br/>
... other fields go here ... <br/><br/>
<?php endforeach ?>

<h1>Type B Products</h1>
<?php foreach ($listRows as $record): ?>
<?php if ($record['table_type'] != "Type B") { continue; } ?>
Name: <?php echo $record['name'] ?><br/>
Title: <?php echo $record['title'] ?><br/>
... other fields go here ... <br/><br/>
<?php endforeach ?>


Basically what we're doing is listing the products multiple times but using that extra line with the "continue" (which means "skip to the next one") to skip over products that aren't of the right type.

Give that a try and let me know if it works for you. If not let me know and I can go into more detail or we can figure something else out.

Hope that helps! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Help separating products list

By _kate_ - April 6, 2008

Yes! That's exactly what I needed - thanks! It's working perfectly now... :)

Just one more quick question... I used the "orderBy" thingy to sort the tables by their dimensions so it's currently showing them from smallest to largest e.g. 1 through to 9. Is there anyway to get it to sort with this field but display them in the other order (e.g. from 9 through to 1)?

Re: [AgentBristow] Help separating products list

By Dave - April 6, 2008

Yes, just add DESC (for descending) after the fieldname like this:

yourFieldName DESC

Hope that helps! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Help separating products list

By _kate_ - April 6, 2008

Cool, thanks! :)

I guess I spoke too soon. I'm having some issues with the page now. It was all working fine at first, but now after I have added more records there are problems.

For example in the first section their are 7 items which were displaying fine, but after I added the rest of the products these no longer show - however what is weird is that some of the items in the other category are showing but not all. All of them in some cats are showing.

Also, I just added the DESC to the sort and now 3 items in the first cat are displaying but not the others...

Re: [AgentBristow] Help separating products list

By Dave - April 6, 2008

My first guess would be that it's only showing the first page of 10. Try setting the perPage option to a high value, such as 999999

$options['perPage'] = '999999';

Since you don't want to page through these results with prev/next links we want to show more than 10 per page.

Let me know if that fixes it.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Help separating products list

By _kate_ - April 6, 2008

That was it! Thanks heaps for all your help! :)