Categories for Dummies - Multi Category, Multi Records Help
7 posts by 2 authors in: Forums > CMS Builder
Last Post: August 6, 2010 (RSS)
By crazyfish - August 6, 2010 - edited: August 6, 2010
On the Catalyst Group website they post studies and reports. http://catalystgrp.com/php/tcgr.php ( click on Studies and Reports )
They enter some studies in more than one category but they only show up in the first category checked off.
"Categories" are in menu type category. In Studies & Reports, field name Category is a field type list, get options from database (advanced) and the section table name is caterories, num, name.
My code is as follows for a list page for category 1
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/var/www/html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
// load records
list($studies_reportsRecords, $studies_reportsMetaData) = getRecords(array(
'tableName' => 'studies_reports',
'perPage' => '10',
'loadUploads' => '0',
'allowSearch' => '0',
'where' => 'category=1',
'orderBy' => 'publish_date DESC',
));
?>
<?php
// Usage: < ?php print maxWords($content, 25); ? >
function maxWords($textOrHtml, $maxWords) {
$text = strip_tags($textOrHtml);
$words = preg_split("/\s+/", $text, $maxWords+1);
if (count($words) > $maxWords) { unset($words[$maxWords]); }
$output = join(' ', $words);
return $output;
}
?>
<?php foreach ($studies_reportsRecords as $record): ?>
<span class="boldblack"><?php echo $record['title'] ?></span><br/>
<?php echo maxWords($record['content'],75) ?>...<br/>
Publish Date: <?php echo date("M, Y", strtotime($record['publish_date'])) ?><br/>
<a href="<?php echo $record['_link'] ?>">Read More</a><br/>
<br/>
<br/>
<?php endforeach ?>
<?php if ($studies_reportsMetaData['invalidPageNum']): ?>
Results page '<?php echo $studies_reportsMetaData['page']?>' not found, <a href="<?php echo $studies_reportsMetaData['firstPageLink'] ?>">start over >></a>.<br/>
<br/>
<?php elseif (!$studies_reportsRecords): ?>
There are no current updates.<br/>
<br/>
<?php endif ?>
<!-- Display Records -->
<!-- Display Page Links -->
<?php if ($studies_reportsMetaData['prevPage']): ?>
<a href="<?php echo $studies_reportsMetaData['prevPageLink'] ?>"><< prev</a>
<?php else: ?>
<< prev
<?php endif ?>
- page <?php echo $studies_reportsMetaData['page'] ?> of <?php echo $studies_reportsMetaData['totalPages'] ?> -
<?php if ($studies_reportsMetaData['nextPage']): ?>
<a href="<?php echo $studies_reportsMetaData['nextPageLink'] ?>">next >></a>
<?php else: ?>
next >>
<?php endif ?>
I know I'm missing something simple here. I thank you for your time.
Re: [crazyfish] Categories for Dummies - Multi Category, Multi Records Help
By Jason - August 6, 2010
The category field in your Studies & Reports table, is it a multi-select drop down? If it is, the problem is CMS Builder stores multiple selects as a list of values separated by a tab character (\t). If you're trying to get records who's category equals "1", try something like this:
// load records
list($studies_reportsRecords, $studies_reportsMetaData) = getRecords(array(
'tableName' => 'studies_reports',
'perPage' => '10',
'loadUploads' => '0',
'allowSearch' => '0',
'where' => "category LIKE '%\t1\t% ' ",
'orderBy' => 'publish_date DESC',
));
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/
Re: [Jason] Categories for Dummies - Multi Category, Multi Records Help
By crazyfish - August 6, 2010
Would that matter?
Re: [crazyfish] Categories for Dummies - Multi Category, Multi Records Help
By Jason - August 6, 2010
CMS Builder will store multi value check boxes and multi value lists the same way. It should still work. Give it a try and let me know if you run into any problems.
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Categories for Dummies - Multi Category, Multi Records Help
By crazyfish - August 6, 2010
Re: [crazyfish] Categories for Dummies - Multi Category, Multi Records Help
By Jason - August 6, 2010
Make sure there is no spaces between the % and the '
So it looks like this:
'where' => "category LIKE '%\t1\t%' ",
Give that a try. If this doesn't work, please attach a copy of the .php file you're working with so I can take a closer look.
Thanks.
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Categories for Dummies - Multi Category, Multi Records Help
By crazyfish - August 6, 2010
Thanks for the help, you guys are great.