Using two viewers causing problems

4 posts by 3 authors in: Forums > CMS Builder
Last Post: August 7, 2011   (RSS)

By andycal - August 2, 2011

Having been away from CMS builder for ages, i've found come back to it and I'm having a frustrating problem.

I've created two 'sections' one is a multi-record list of pages, the other is a multi-record list of 'side bars'. I create three side bars and then every time I add a page I assign one of the side bars.

Right, so I've put this in the header:

<?php

// this bit gets the content


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/weget123/public_html/airguard/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records
list($pagesRecords, $pagesMetaData) = getRecords(array(
'tableName' => 'pages',
'where' => whereRecordNumberInUrl(1),
'loadUploads' => '0',
'limit' => '1',
));
$pagesRecord = @$pagesRecords[0]; // get first record

// show error message if no matching record is found
if (!$pagesRecord) { dieWith404("Record not found! Pages"); }


// find which sidebar to use:
$sidebar = $pagesRecord['side_bar'];

?>
<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/weget123/public_html/airguard/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records
list($side_barsRecords, $side_barsMetaData) = getRecords(array(
'tableName' => 'side_bars',
'where' => 'num = '.$sidebar,
'limit' => '1',
));
$side_barsRecord = @$side_barsRecords[0]; // get first record

// show error message if no matching record is found
if (!$side_barsRecord) { dieWith404("Record not found!side"); }


As you can see, I pop the side bar value into a variable "$sidebar" and then try to call it in the second bit of code, however each time I do this the number is ignored and the code grabs "num" from the URL again giving the wrong result.

I guess I'm doing something fundamentally wrong, but I'll be jiggered if I know what!

Re: [andycal] Using two viewers causing problems

By Steve99 - August 3, 2011

Hello.

Change your load side bars code to this:

list($side_barsRecords, $side_barsMetaData) = getRecords(array(
'tableName' => 'side_bars',
'where' => 'num = "'.$sidebar.'"',
'limit' => '1',
));

That should fix it. Also, you only need to load the viewer library once.

Hope this helps.

Re: [andycal] Using two viewers causing problems

By Jason - August 3, 2011

Hi,

Another thing you can try is to turn off automatic searching on your query like this:

list($side_barsRecords, $side_barsMetaData) = getRecords(array(
'tableName' => 'side_bars',
'where' => 'num = "'.$sidebar.'"',
'limit' => '1',
'allowSearch' => false,
));


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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