Need Help with Category Setup
3 posts by 2 authors in: Forums > CMS Builder
Last Post: February 8, 2010 (RSS)
By kevbarker - February 7, 2010 - edited: February 7, 2010
I am working on a site where I need to display a list of categories and when one of the categories is clicked display a list of the records which belong in that category. I am close to what I need, but can't seem to figure out how to display NO records for the initial index page. Right now it list all the categories as desired, but also shows ALL records created. I would like for no records to be displayed until a category or sub-category is clicked. I followed the tutorial Chris posted and got this far. Anyone know what I'm missing? How can I have it display NO records on the index page until a category is selected?
Here is a link to the basic index page:
http://www.thelawsonshouse.com/employee/
As you will see it displays ALL records on page and then when a category is clicked, will display associated records for that category.
Thanks in advance for any suggestions.
Kevin
Here is a link to the basic index page:
http://www.thelawsonshouse.com/employee/
As you will see it displays ALL records on page and then when a category is clicked, will display associated records for that category.
Thanks in advance for any suggestions.
Kevin
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
require_once "/home/kevbarker/thelawsonshouse.com/admin/lib/viewer_functions.php";
list($categoriesRecords, $selectedCategory) = getCategories(array(
'tableName' => 'document_categories',
'categoryFormat' => 'onelevel',
));
list($corp_documentsRecords, $corp_documentsMetaData) = getRecords(array(
'tableName' => 'corp_documents',
));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
</head>
<body>
<h1>Document Categories</h1>
<ul>
<?php foreach ($categoriesRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>
<?php if ($categoryRecord['_isSelected']): ?><b><?php endif ?>
<a href="?category=<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php if ($categoryRecord['_isSelected']): ?></b><?php endif ?>
<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach ?>
</ul>
<h1>Documents Found </h1>
<?php foreach ($corp_documentsRecords as $record): ?>
<a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a><br/>
<?php endforeach ?>
<?php if (!$corp_documentsRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records -->
</body>
</html>
Re: [kevbarker] Need Help with Category Setup
By Dave - February 8, 2010 - edited: February 8, 2010
Hi kevbarker,
Try filtering the records in corp_documents based on the selected category num. If there is no selected category num this should return no records. Change my code if your category field isn't called categoryNum.
Hope that helps!
Try filtering the records in corp_documents based on the selected category num. If there is no selected category num this should return no records. Change my code if your category field isn't called categoryNum.
list($corp_documentsRecords, $corp_documentsMetaData) = getRecords(array(
'tableName' => 'corp_documents',
'where' => "categoryNum = '" .mysql_escape(@$selectedCategory['num']) . "'",
));
Hope that helps!
Dave Edis - Senior Developer
interactivetools.com
interactivetools.com
Re: [Dave] Need Help with Category Setup
That fixed it Dave. Thanks for your help!
Kevin
Kevin