...And Then My Brain Turned to Cheese!
3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 11, 2011 (RSS)
By Perchpole - April 8, 2011
Hello, All
I haven't written in for a while so this little puzzler marks a fitting return to the fold.
There are 3 elements to consider:
1) Category pages
2) Panels
3) Boxes
Each element is nested inside the other. The boxes sit the panels which sit on the Category pages.
A panel can be assigned to any of the Category pages (via a multi-select menu called "categorySelector").
Multiple boxes can be assigned to each panel (each via a multi-select menu called "panelSelector").
Thus far I have the panels rendering on the right Category pages, using the following code:
...which seems to work.
What I can't work out is how to filter the right boxes to appear on the panels.
I'm working with something like this...
It doesn't work. I'm sure I'm close but I can't quite nail it....
Help!
:0)
Perch
I haven't written in for a while so this little puzzler marks a fitting return to the fold.
There are 3 elements to consider:
1) Category pages
2) Panels
3) Boxes
Each element is nested inside the other. The boxes sit the panels which sit on the Category pages.
A panel can be assigned to any of the Category pages (via a multi-select menu called "categorySelector").
Multiple boxes can be assigned to each panel (each via a multi-select menu called "panelSelector").
Thus far I have the panels rendering on the right Category pages, using the following code:
list($panelRecords, $panelMetaData) = getRecords(array(
'tableName' => 'panel',
'where' => "categorySelector LIKE '%\t{$selectedCategory['num']}\t%'",
));
...which seems to work.
What I can't work out is how to filter the right boxes to appear on the panels.
I'm working with something like this...
$activePanels = array();
foreach($panelRecords as $panels){
if($panels['categorySelector'] == $selectedCategory['num']){
$activePanels[] = $panels;
}
}
list($boxesRecords, $boxestMetaData) = getRecords(array(
'tableName' => 'boxes',
'where' => " '%\t{panelSelector}\t%' IN ('%\t{$activePanels}\t%')",
));
It doesn't work. I'm sure I'm close but I can't quite nail it....
Help!
:0)
Perch
Re: [Perchpole] ...And Then My Brain Turned to Cheese!
By robin - April 11, 2011
Hey Perch,
Since you are doing 'LIKE' searches you can't use the IN function. So we need to change your $activePanels array a bit. Then implode it to mysql OR conditions after that.
Using implode can be a bit hard to understand at first, but it can be really handy in situations like this.
http://php.net/manual/en/function.implode.php
Here is a possible solution:
Hope that helps,
Robin
Since you are doing 'LIKE' searches you can't use the IN function. So we need to change your $activePanels array a bit. Then implode it to mysql OR conditions after that.
Using implode can be a bit hard to understand at first, but it can be really handy in situations like this.
http://php.net/manual/en/function.implode.php
Here is a possible solution:
foreach($panelRecords as $panels){
if($panels['categorySelector'] == $selectedCategory['num']){
$activePanels[] = "'%\tpanelSelector\t%' = '%\t$panels\t%'"
}
}
$activePanelsWhereCondition = '';
$activePanelsWhereCondition = implode(" OR ", $activePanels);
list($boxesRecords, $boxestMetaData) = getRecords(array(
'tableName' => 'boxes',
'where' => $activePanelsWhereCondition,
));
Hope that helps,
Robin
Robin
Programmer
interactivetools.com
Programmer
interactivetools.com
Re: [robin] ...And Then My Brain Turned to Cheese!
By Perchpole - April 11, 2011
Hi, Robin -
I feel another fondue moment coming on just looking at this!
Seriously, this is great. I really love ingenious stuff like this.
:0)
Perchpole
I feel another fondue moment coming on just looking at this!
Seriously, this is great. I really love ingenious stuff like this.
:0)
Perchpole