Simple question about 2 linked editor
3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 10, 2009 (RSS)
By willbegood - March 10, 2009
Hello, i have an editor for products
A product is define as below
- Name of the product
- Description text
- Category (this one is "linked" with another editor defined below)
I have a second editor for "Category product" define as below
- Category Name
- Category Logo
In my first editor for "category" i want to populate the list in order to show "categorie name" recorded in my second editor.
But i also need the field category logo to display in my page online.
I want to be able my product list display as this
Category Name (1)
+ Category Logo (1)
- Product 1
- Product 2
- Product 3....
--------------------
Category Name (2)
+ Category Logo (2)
- Product 4
- Product 5
- Product 6....
I know how to do this only with Category name my problem is to use another field in the table "category product)
I hope it's clear enough.
I see some SELECT num, CONCAT_WS but don't really understand how to use it my case.
Thanks a lot
A product is define as below
- Name of the product
- Description text
- Category (this one is "linked" with another editor defined below)
I have a second editor for "Category product" define as below
- Category Name
- Category Logo
In my first editor for "category" i want to populate the list in order to show "categorie name" recorded in my second editor.
But i also need the field category logo to display in my page online.
I want to be able my product list display as this
Category Name (1)
+ Category Logo (1)
- Product 1
- Product 2
- Product 3....
--------------------
Category Name (2)
+ Category Logo (2)
- Product 4
- Product 5
- Product 6....
I know how to do this only with Category name my problem is to use another field in the table "category product)
I hope it's clear enough.
I see some SELECT num, CONCAT_WS but don't really understand how to use it my case.
Thanks a lot
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:
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.
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
interactivetools.com
Re: [Dave] Simple question about 2 linked editor
By willbegood - March 10, 2009
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?
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?