Need to fetch category record.

3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 10, 2010   (RSS)

By rconring - March 8, 2010

I have just created an animal adoption section on a website and all is working as expected except for one small problem.
I have used a category/subcategory menu on an introduction page on animal adoption from which, when a subcategory is selected, links to a list page of animals (animals.php) for adoption in that subcategory. This all works fine using the categroy number at the end of the url. animals.php?animal_category=2
When the listing page loads, I want to fetch some information from the category record to display at the top of the animal listing page, the breadcrumb, the category description and some other stuff.
I cannot figure out how to get the related info from the animal_categories record.
Here is the viewer code for the animals.php page

list($animal_categoriesRecords, $animal_categoriesMetaData) = getCategories(array(
'tableName' => 'animal_categories',
));

list($animalsRecords, $animalsMetaData) = getRecords(array(
'tableName' => 'animals',
'where' => 'hidden != 1',
));

Need to fetch the appropriate category record and display the info here.

Then display the listing here ...
<?php foreach ($animalsRecords as $record): ?>
display code .....
<?php endforeach ?>

I hope I have made myself clear.
Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987

Re: [rconring] Need to fetch category record.

By Chris - March 9, 2010

Hi Ron,

getCategories returns a list of records and the "selected" record, not a list of records and "metaData". You'll want to change this:

list($animal_categoriesRecords, $animal_categoriesMetaData) = getCategories(array(

to this:

list($animal_categoriesRecords, $animal_categoriesSelected) = getCategories(array(

By default, getCategories() decides which record is "selected" using the last number in the URL, which I think will just do the right thing for you here. You can then use fields from the $animal_categoriesSelected record to display the info you want.

I hope this helps! Please let me know if you have any questions.
All the best,
Chris