Show selected category records

4 posts by 2 authors in: Forums > CMS Builder
Last Post: December 12, 2013   (RSS)

By Toledoh - December 9, 2013 - edited: December 9, 2013

Hi Guys, 

I've got the following that produces 2 navigational block.  Main and Section.  The Main Nav is showing the top level items, the Section Nav is showing the 2nd level.  But how do I change it to show only the 2nd level from the selected main level?

  // load detail record
  list($pagesRecords, $pagesMetaData) = getRecords(array(
    'tableName'   => 'pages',
    'where'       => whereRecordNumberInUrl(1), // If no record # is specified then latest record is shown
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $detailRecord = @$pagesRecords[0]; // get first record
  if (!$detailRecord) { dieWith404("Record not found!"); } // show error message if no record found

  // load records for 'MAIN NAVIGATION'
  list($level1Records, $level1MetaData) = getRecords(array(
    'tableName'   => 'pages',
    'loadUploads' => true,
    'allowSearch' => false,
    'where'       => "depth = 0"
  ));

  // load records for 'SECTION NAVIGATION'
  list($pagesRecords, $pagesMetaData) = getRecords(array(
    'tableName'   => 'pages',
    'orderBy'     => '',   // use default database order
    'loadUploads' => false,
    'allowSearch' => false,
    'where'       => "depth = 1"
  ));

Cheers,

Tim (toledoh.com.au)

Any thoughts on this guys?

Cheers,

Tim (toledoh.com.au)

By Dave - December 12, 2013

Hi Tim, 

So it sounds like your selected main level is stored in $detailRecord?

If so you could do something like this:

// load records for 'SECTION NAVIGATION'
list($pagesRecords, $pagesMetaData) = getRecords(array(
  'tableName'   => 'pages',
  'orderBy'     => '',   // use default database order
  'loadUploads' => false,
  'allowSearch' => false,
  'where'       => "depth = 1 AND parentNum = '" .mysql_escape($detailRecord['num']). "' ",
));

Note that you'll need to make sure the "parentNum, num, etc" fields match whatever fields you are using.

Let me know if that works for you.

Dave Edis - Senior Developer
interactivetools.com