Selecting Category List Top Level

5 posts by 2 authors in: Forums > CMS Builder
Last Post: June 7, 2011   (RSS)

By theclicklab - June 5, 2011

I am trying to restrict a generated list (category list) to the top level only and need some assistance...

The reference page is here: http://www.sailconnections.com/yacht-type.php/sailing-1/

The original select code was:

$numType="%\t".$yacht_typeRecord['url']."\t%";
list($yachtsRecords, $yachtsMetaData) = getRecords(array(
'tableName' => 'yachts',
'where' => "type LIKE '$numType'" . ' AND active ="1"' . ' AND hide ="0"',
'useSeoUrls' => true,
'allowSearch' => false,
));


which I need to change to a category format. I tried this...

$numType="%\t".$yacht_typeRecord['url']."\t%";
list($yachtsRecords, $selectedCategory) = getCategories(array(
'tableName' => 'yachts',
'where' => "type LIKE '$numType'" . ' AND active ="1"' . ' AND hide ="0"',
'categoryFormat' => 'onelevel', // showall, onelevel, twolevel
'useSeoUrls' => true,
'allowSearch' => false,
));


but can't have the "where" statement included. So not sure how to achieve this.

The actual code to generate the list is:

<?php foreach ($yachtsRecords as $record): ?>

<?php
$values = getListValues('yachts','destinations',$record['destinations']);
$labels = getListLabels('yachts','destinations',$record['destinations']);
$valuesToLabels = array_combine($values, $labels);
?>

<?php $count2=0; ?>
<?php foreach ($valuesToLabels as $value => $label): ?>
<?php $where ="num =".intval($value)." AND suppress=1"; if(mysql_select_count_from('destinations',$where)){ continue; } ?>
<?php echo ($count2==0)? "" : ", " ?><a href="/destination.php/<?php echo str_replace(" ","-",strtolower($label."-".$value)); ?>/">
<?php echo htmlspecialchars($label); ?></a><?php $count2++;?>
<?php endforeach ?>

<?php endforeach ?>


Have attached the actual page as well in case this is useful... the list starts at line 96.

Suggestions, tips, greatly appreciated.

Thanks.

Re: [theclicklab] Selecting Category List Top Level

By robin - June 6, 2011

Hey Jan,

You might be able to stay with using getRecords(), and just add make a change to your where. To just show the top level we can use a depth condition. Something like:

list($yachtsRecords, $yachtsMetaData) = getRecords(array(
'tableName' => 'yachts',
'where' => "type LIKE '$numType' AND active='1' AND hide='0' AND depth='0'",
'useSeoUrls' => true,
'allowSearch' => false,
));


I cleaned up the quotes a little bit too.

Hope that helps,
Robin
Robin
Programmer
interactivetools.com

Re: [robin] Selecting Category List Top Level

By theclicklab - June 6, 2011

Hi robin, that gives me the following error:

MySQL Error: Unknown column 'depth' in 'where clause'

Any other suggestions?

Many Thanks
Jan

Re: [theclicklab] Selecting Category List Top Level

By robin - June 7, 2011

Hey Jan,

That's surprising that there is no depth column in a category section. Yachts is a category section right?

Thanks,
Robin
Robin
Programmer
interactivetools.com