Listing Records that have Multiple Category Options
8 posts by 5 authors in: Forums > CMS Builder
Last Post: November 3, 2010 (RSS)
By studio-a - April 2, 2010
01. We have created a table for CATEGORY so that our client can add or remove category records as they see fit.
02. We have another table for JOBS which references the CATEGORY table and is displayed within the admin section as check boxes for multiple selections. Each Job record may have more than one Category (hence the check box cross references).
03. We want to display a Weekly New Job listings on the home page.
04. Rather than list the Job by its title, the client prefers to list the new posting by its related category and link to the Listing Page for that category.
05. The Weekly New Jobs will be coded as an "include" for the home page file.
06. Since each Job may have more than one category, how do we
-- A) Limit the New listing to ONE category being displayed for that one record?
-- B) Not repeat the category being displayed from another job record within the loop for the include?
-- C) Link each Job listing (as a category name) to the list page for that category?
This is what we have started, but needs serious help! We realize the echo join is wrong, but it’s the only way we know how to output something that works without errors.
<?php
require_once dirname(dirname(__FILE__)) . "/cmsAdmin/lib/viewer_functions.php";
list($jobsRecords, $jobsMetaData) = getRecords(array(
'tableName' => 'jobs',
'orderBy' => 'updatedDate DESC',
'limit' => '10',
));
?>
<?php foreach ($jobsRecords as $record): ?>
<a href=" listJobs.php?jobs=<?php echo $record['category '] ?>”>
<?php echo join(', ', getListLabels('jobs', 'category', $record['category'])); ?>
</a><br/>
<?php endforeach ?>
<?php if (!$jobsRecords): ?>
No records were found.<br/>
<br/>
<?php endif ?>
Your help is appreciated!
Re: [studio-a] Listing Records that have Multiple Category Options
By Chris - April 5, 2010
I'm confused about 6.a: how can a single category be displayed for a job that could belong to multiple categories? Should a category be picked at random?
Here's an approach which gathers up all the categories referenced by the jobs (preventing duplicates) and then displays them all.
<?php
require_once dirname(dirname(__FILE__)) . "/cmsAdmin/lib/viewer_functions.php";
list($jobsRecords, $jobsMetaData) = getRecords(array(
'tableName' => 'jobs',
'orderBy' => 'updatedDate DESC',
'limit' => '10',
));
$categoryNums = array();
foreach ($jobsRecords as $record) {
foreach (explode("\t", trim($record['category'])) as $catNum) {
$categoryNums[$catNum] = true;
}
}
?>
<?php foreach (array_keys($categoryNums) as $catNum): ?>
<a href="listJobs.php?jobs=<?php echo $catNum ?>">
<?php echo join('', getListLabels('jobs', 'category', $catNum)); ?>
</a><br/>
<?php endforeach ?>
<?php if (empty($categoryNums)): ?>
No job categories were found.<br/>
<br/>
<?php endif ?>
Does this help? Please let me know if you have any questions.
Chris
Re: [chris] Listing Records that have Multiple Category Options
By Mikey - November 2, 2010 - edited: November 2, 2010
I've racked my brains over this and can't seem to figure this out. Here's what I'm trying to do. I've got a Media/Photo Gallery ($media_gallery) that has Categories ($media_categories) pulled in from a section field using the advanced option and I've also created a Date field for the Media/Photo Gallery ($media_gallery) section so when I upload new photos or media to the Media/Photo Gallery I can assign a Date value to the media and/or photos.
In the form below I have two drop down menus to allow site visitors to drill down on the media and photos by Category and/or Date.
The Category search filter is working fine, but for my Date drop down search filter, I'm getting repeating dates such as 2009, 2009, 2010, 2010, 2010... basically a date for each photo of media item that has been uploaded.
I'm trying to trim the date results in the Date drop down menu so that it only displays one 2009, 2010, 2011, and so on. So when someone chooses the Date filter and selects a Year, it returns all results for media and photos uploaded for the year selected. And/Or if the site visitor chooses a Category filter and a Date filter, it would return results for the Category chosen based on the Date filter selected.
Can you shed some light on this and what I need to do to get this working?
Thanks Zick
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
// load viewer library
$libraryPath = 'abcsite/lib/viewer_functions.php';
$dirsToCheck = array('/home/content/a/b/c/site/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($media_galleryRecords, $media_galleryMetaData) = getRecords(array(
'tableName' => 'media_gallery',
'perPage' => '9',
));
// load records
list($media_categoriesRecords, $media_categoriesMetaData) = getRecords(array(
'tableName' => 'media_categories',
));
<div id="media_search">
<!-- search filter -->
<!-- search media category filter -->
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<select name="gallery_categories_query">
<option value="">categories</option>
<?php foreach ($media_categoriesRecords as $categoryRecord): ?>
<option value="<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?></option>
<?php endforeach ?>
</select>
<!-- search media date filter -->
<select name="date_query">
<option value="">Year</option>
<?php foreach ($media_galleryRecords as $record): ?>
<option value="<?php echo date("Y", strtotime($record['date'])) ?>"><?php echo date("Y", strtotime($record['date'])) ?></option>
<?php endforeach ?>
</select>
<input name="submit" type="submit" class="button" value="begin">
</form>
<!-- /search filter --></div>
Re: [zick] Listing Records that have Multiple Category Options
By Toledoh - November 2, 2010
I expect that something similar to this thread would work... but it's pushng my grey matter a bit far!
http://www.interactivetools.com/iforum/Products_C2/CMS_Builder_F35/Listing_Records_that_have_Multiple_Category_Options_P79113/gforum.cgi?post=72447;search_string=group;t=search_engine#72447
Tim (toledoh.com.au)
Re: [Toledoh] Listing Records that have Multiple Category Options
By Toledoh - November 3, 2010
http://www.interactivetools.com/iforum/Products_C2/CMS_Builder_F35/gforum.cgi?post=83217;search_string=populate%20drop%20down;t=search_engine#83217
Tim (toledoh.com.au)
Re: [zick] Listing Records that have Multiple Category Options
By Jason - November 3, 2010
Try using this code:
(changes highlighted in red)
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
// load viewer library
$libraryPath = 'abcsite/lib/viewer_functions.php';
$dirsToCheck = array('/home/content/a/b/c/site/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($media_galleryRecords, $media_galleryMetaData) = getRecords(array(
'tableName' => 'media_gallery',
'perPage' => '9',
));
// load records
list($media_categoriesRecords, $media_categoriesMetaData) = getRecords(array(
'tableName' => 'media_categories',
));
//get unique years
$years=array();
foreach($media_galleryRecords as $record){
$tmpYear = date("Y",strtotime($record['date']));
$years[$tmpYear]=$tmpYear;
}
?>
<div id="media_search">
<!-- search filter -->
<!-- search media category filter -->
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<select name="gallery_categories_query">
<option value="">categories</option>
<?php foreach ($media_categoriesRecords as $categoryRecord): ?>
<option value="<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?></option>
<?php endforeach ?>
</select>
<!-- search media date filter -->
<select name="date_query">
<option value="">Year</option>
<?php foreach($years as $year):?>
<option value="<?php echo $year;?>"><?php echo $year;?></option>
<?php endforeach ?>
</select>
<input name="submit" type="submit" class="button" value="begin">
</form>
<!-- /search filter --></div>
This code first creates an array of years. Any duplicates overwrite each other so you can only have 1 of each year. The foreach loop inside your <select> simply uses the $years array for it's options.
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] Listing Records that have Multiple Category Options
By Mikey - November 3, 2010
Thanks for the help Jason!
Re: [Toledoh] Listing Records that have Multiple Category Options
By Mikey - November 3, 2010
Zick