Category Links

2 posts by 2 authors in: Forums > CMS Builder
Last Post: December 13, 2011   (RSS)

Re: [Kenny] Category Links

By Jason - December 13, 2011

Hi Kenny,

The issue here is that the category field in your products section is only storing the category record number, not the title. If you want to use the title you have a couple of options:

1) Change the option value from num to title for your drop down. You'll have to re-associate all your products to categories, but after that, you can search for a category by title instead of num. If the name of a category ever changes, however, these associations will break.

2) Another option would be to do your search manually, first getting the category record then using that num in your products search. NOTE: for this to work well, a category title will have to be unique. This example also assumes your using CMSB version 2.08 or higher:

$options = array(
'tableName' => 'products',
);

if (@$_REQUEST['category']) {

$category = mysql_get('category', null, "title = '".mysql_escape(@$_REQUEST['category'])."'");
if (!$category) { die("Error! Category Not Found!"); }

$options['allowSearch'] = false;
$options['where'] = "category = '".mysql_escape($category['num'])."'";

}

list($productRecords, $productMetaData) = getRecords($options);


Hope this helps get you started.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/