Use Value Set by Parent?

2 posts by 2 authors in: Forums > CMS Builder
Last Post: May 28, 2012   (RSS)

Re: [Perchpole] Use Value Set by Parent?

By Jason - May 28, 2012

Hi Perch,

You could try something like this:

if(isset($selectedCategory['selectMarginRight'])) {

list($marginRight, $marginRightMetaData) = getRecords(array(
'tableName' => 'margin',
'allowSearch' => false,
'where' => " num = '".intval($selectedCategory['selectMarginRight'])."' ",
'orderBy' => 'title',
));
$marginR = @$marginRight[0];
}
elseif ($selectedCategory['_hasParent']) {

//get parent record
$parentCategory = mysql_get("categories", $selectedCategory['parentNum']);
if ($parentCategory && @$parentCategory['selectMarginRight']) {

list($marginRight, $marginRightMetaData) = getRecords(array(
'tableName' => 'margin',
'allowSearch' => false,
'where' => " num = '".intval($parentCategory['selectMarginRight'])."' ",
'orderBy' => 'title',
));

$marginR = @$marginRight[0];

}
else {
die("Error - no value for selectMarginRight found!");
}

}
else {
die("ERROR - selectMarginRight not selected in either selected category or category parent!");
}


A couple of assumptions where made in this code. First that your category section was called categories. You may need to update this value in the mysql_get() function call.

Second, it's assumed that if no value for selectedMarginRight can be found in the parent record, or that there is no parent record, an error should be produced (see the 2 die() statements). This can be replaced with something else if this is not really an error condition.

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/