Get articles from different tables (subcategories)

4 posts by 2 authors in: Forums > CMS Builder
Last Post: September 18, 2013   (RSS)

By Jesus - September 18, 2013

Hello,

Here's another issue I need to get solved... will try my best to explain this properly.

I've a products category with 3 articles on it. Each article represents one product category.

Each product category has their own table (subcategories).

I want my detail page on products to display the article list for each particular subcategory.

Something like:

/products/category-one/

/products/category-two/

/products/category-three/

Where on category-one file I'll display the article list from sub-category-one, on category-two file I'll display the article list from sub-category-two and on category-three file I'll display the article list from sub-category-three. 

The thing here its that I need an IF statement on my detail page on products so based on which category I'm it will display the proper subcategory list.

I hope I explain this properly and it is clear. Thanks in advance for your help!

Jesus

By Jason - September 18, 2013

Hi Jesus,

That solution would definitely work.  The only issue I can see is that on any given page, you would load at least 3 record sets that would never be used.  To help keep the code clean, what you can do is use an if statement to figure out which table you should be getting records from and only load a single record set.

NOTE:  In this example I'm assuming that your tables are called sub1, sub2, etc

if ($productsRecord['category'] == "SUB1") {
    $tableName = 'sub1';
  }
  elseif ($productsRecord['category'] == "SUB2") {
    $tableName = 'sub2';
  }
  elseif ($productsRecord['category'] == "SUB3") {
    $tableName = 'sub3';
  }
  else {
    $tableName = 'sub4';
  }
  
  list($subcategoryRecords, $subMetaData) = getRecords(array(
    'tableName'    =>  $tableName,
    'allowSearch'  =>  false,
  ));

This way, in your code you can always just output $subcategoryRecords without having to worry about which record set you need.

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/

By Jesus - September 18, 2013

Munch, much better :)

Thanks!!