Simple question about 2 linked editor

3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 10, 2009   (RSS)

Re: [willbegood] Simple question about 2 linked editor

By Dave - March 10, 2009

Hi Willbygood,

You're on the right track. How many categories for you think you'll have?

One way to do it is to load all the categories with one block of viewer code, and then all the products in another and then loop over them with something like this:

<?php foreach ($categoryRecords as $category): ?>
<?php echo $category['name'] ?>
... insert code to show category image ...

<?php foreach ($productRecords as $product): ?>
<?php if ($product['categoryNum'] != $category['num']) { continue; }
... show product details here ...
<?php endforeach ?>

<?php endforeach ?>


And when you link the product category field to the category section, use "num" as the value and "name" as the label. The category num won't change, but if you use name for both and change a category name you'll lose the link.

The code above loops over each category, displays it, then loops over each product, skipping the ones that aren't in the current category.

Hope that helps! Give it a try and let me know how it goes.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Simple question about 2 linked editor

Hello Dave, i think i will have 20 categories max.
To use your method, may i have to configure my field category (list) with some get option from mysql query?

what should be the php header code in your case should i generate code for both listing category & product table?