Help separating products list

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

By _kate_ - April 5, 2008

First of all I have only briefly used this product but it's absolutely amazing!

I am trying to integrate this into an existing website for a client who wants the layout to remain the same. They have a list of products (Tables) broken into different table categories. The page layout is very basic (they have a new table for each different category with a heading for each).

I worked out how to make the products page and put it into the layout, however I need only products of a certain type to display within a table of its own without being joined to the others - so I made a list field called "table_type" and put all the different types in.

I figured out I could bring up only the items I wanted by using the following URL:
http://www.mywebsite.com/tablesList.php?table_type=Trestle

however I still can't figure out how to get the code on tablesList.php to display only the table type I want so I can put it into the correct spot on the page and paste in each table type. I basically need it to display a list of the products, however only display the table type that I specify. All the different table types will be on the one page.

Hopefully that make sense :) Any help is appreciated!

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: [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! :)