Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
Show field from linked category section

 

 


videopixel
User

Aug 31, 2010, 1:03 AM

Post #1 of 4 (673 views)
Shortcut
Show field from linked category section Can't Post

almost live with my site. But still some problems…

I have a multi record section called "links" with the following fields:
title, url, category. The category is a drop down list populated from another multi record section called "links_categories"
The "links_categories" has the fields: title, icon. The icon is an upload field… pretty basic...

Everything is working in the back and front-end only one thing: how do i show the icon from the category with the links?


Code
list($linksRecords, $linksMetaData) = getRecords(array( 
'tableName' => 'links',
'perPage' => '10',
'orderBy' => 'RAND()',
'allowSearch' => '0',
));


body:


Code
<?php foreach ($linksRecords as $record): ?> 
(here i want to show the icon from the category that is linked to the title)
<?php echo $record['title'] ?>
<?php echo $record['url'] ?>
<?php endforeach ?>



thanks!


Jason
Staff / Moderator


Aug 31, 2010, 9:41 AM

Post #2 of 4 (658 views)
Shortcut
Re: [videopixel] Show field from linked category section [In reply to] Can't Post

Hi,

What you need to do is to create an array of categories that you can then access when you're outputting your links records. Exactly how you do this will depend on exactly how you're linking your categories to your links (ie, what is the value field of the dropdown?). In this example, it's assuming you're using the num field in the links_category table.

example:

You can put this code up where you're selecting your records

Code
 list($categoryRecords,$categoryMetaData) = getRecords(array( 
'tableName' => 'links_category',
'allowSearch' => false,
));

$categoryNumToRecord=array();
foreach($categoryRecords as $category){
$categoryNumToRecord[$category['num']]=$category;
}


The variable $categoryNumToRecord is an array of category records, using their 'num' field as an index.

You can then get at the correct category record when outputting your content like this:


Code
<?php foreach ($linksRecords as $record): ?>  

<?php $categoryRecord = $categoryNumToRecord[$record['category']];?>

<?php echo $record['title'] ?>
<?php echo $record['url'] ?>
<?php endforeach ?>


You can now use the variable $categoryRecord to output any information stored in that category record.

Hope this helps get you started.
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/ 


videopixel
User

Aug 31, 2010, 5:15 PM

Post #3 of 4 (650 views)
Shortcut
Re: [Jason] Show field from linked category section [In reply to] Can't Post

I don't need an 'array' to see my category, because that code is already generated in the code generator of CMSB.

It's the 'icon' (upload) that i want to see from my categories...


Thanks anyway!


Jason
Staff / Moderator


Sep 1, 2010, 8:46 AM

Post #4 of 4 (644 views)
Shortcut
Re: [videopixel] Show field from linked category section [In reply to] Can't Post

Hi,

The array for the category is not just the category name, but the whole category record, this would include the icon field. Your other record will just have the category name, but no other information about the category.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/