category records - Get options from database - displayed as bullets
2 posts by 2 authors in: Forums > CMS Builder
Last Post: January 17, 2011 (RSS)
By Mikey - January 15, 2011
I'm pulling category records into a single called "Products" page. I've created a list checkbox field called "Keywords" and I'm using the "Get options from database (advanced).
List Options: Get options from database (advanced)
Section Tablename: keywords
Use this field for option values: num
Use this field for option labels: name
I'm trying to make the keywords appear as a list with bullets in the code below. But it's returning all of my Keyword category records and not just those I have selected the checkbox for within Products. I also intend to use this code on other site pages as a dropdown selection menu for a few site forms for drilling down on categories. This code works, but it's just not limiting only categories that have been selected for the page it is related to and instead it reflects all category records. Can anyone shed some light on how to make this code show only category records that have been checked within the Products record?
Here's the original code generated by CMS Builder to display the keywords:
<?php echo join(', ', getListLabels('products', 'keywords', $productsRecord['keywords'])); ?>
///////////////////////////////// keywords as bulltets ////////////////////////////////////
//<?php echo join(', ', getListLabels('products', 'keywords', $productsRecord['keywords']));
list($productsBulletsRecords, $productsBulletsMetaData) = getRecords(array(
'tableName' => 'keywords',
'orderBy' => "name asc",
));
//compile products Bullet array
$currentDrill = array();
foreach($productsBulletsRecords as $record){
//if($record['depth'] < 1) { continue; };
//temporary array of elements for a particular record
$temp = trim($record['name']);
$temp = ucfirst($temp); // Returns a string with the first character of str capitalized
$temp = ucwords($temp); // Returns a string with the first character of each word in str capitalized
$temp = explode("\t",$temp);
foreach($temp as $item){
$item=str_replace("<br/>","",$item);
if(!in_array($item,$currentDrill)){ //add a new item to the array
$currentDrill[$item]=$item;
}}}
//sort $currentDrill
sort($currentDrill);
Here's my page code where the bullets will appear:
<ul><?php foreach ($currentDrill as $keywords): ?>
<li><?php echo $keywords;?></li>
<?php endforeach ?> </ul>
List Options: Get options from database (advanced)
Section Tablename: keywords
Use this field for option values: num
Use this field for option labels: name
I'm trying to make the keywords appear as a list with bullets in the code below. But it's returning all of my Keyword category records and not just those I have selected the checkbox for within Products. I also intend to use this code on other site pages as a dropdown selection menu for a few site forms for drilling down on categories. This code works, but it's just not limiting only categories that have been selected for the page it is related to and instead it reflects all category records. Can anyone shed some light on how to make this code show only category records that have been checked within the Products record?
Here's the original code generated by CMS Builder to display the keywords:
<?php echo join(', ', getListLabels('products', 'keywords', $productsRecord['keywords'])); ?>
///////////////////////////////// keywords as bulltets ////////////////////////////////////
//<?php echo join(', ', getListLabels('products', 'keywords', $productsRecord['keywords']));
list($productsBulletsRecords, $productsBulletsMetaData) = getRecords(array(
'tableName' => 'keywords',
'orderBy' => "name asc",
));
//compile products Bullet array
$currentDrill = array();
foreach($productsBulletsRecords as $record){
//if($record['depth'] < 1) { continue; };
//temporary array of elements for a particular record
$temp = trim($record['name']);
$temp = ucfirst($temp); // Returns a string with the first character of str capitalized
$temp = ucwords($temp); // Returns a string with the first character of each word in str capitalized
$temp = explode("\t",$temp);
foreach($temp as $item){
$item=str_replace("<br/>","",$item);
if(!in_array($item,$currentDrill)){ //add a new item to the array
$currentDrill[$item]=$item;
}}}
//sort $currentDrill
sort($currentDrill);
Here's my page code where the bullets will appear:
<ul><?php foreach ($currentDrill as $keywords): ?>
<li><?php echo $keywords;?></li>
<?php endforeach ?> </ul>
Re: [zick] category records - Get options from database - displayed as bullets
By Jason - January 17, 2011
Hi,
In your code, you have a record variable $productsRecord. Is this the record you want to display?
In your code your creating $currentDrill array with all the records from the 'keywords' table.
If you want to get an array of just the list labels for the record your current working with, you could do it like this:
If you're using CMS Builder version 2.04 or higher, you can use the :labels pseudo field like this:
Is this more what you're looking for?
Hope this helps.
In your code, you have a record variable $productsRecord. Is this the record you want to display?
In your code your creating $currentDrill array with all the records from the 'keywords' table.
If you want to get an array of just the list labels for the record your current working with, you could do it like this:
<?php $keywords = getListLabels('products', 'keywords', $productsRecord['keywords']);?>
<ul><?php foreach ($keywords as $keyword): ?>
<li><?php echo $keyword;?></li>
<?php endforeach ?> </ul>
If you're using CMS Builder version 2.04 or higher, you can use the :labels pseudo field like this:
<ul><?php foreach ($productsRecord['keywords:labels'] as $keyword): ?>
<li><?php echo $keyword;?></li>
<?php endforeach ?> </ul>
Is this more what you're looking for?
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/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/