Related Records?
34 posts by 6 authors in: Forums > CMS Builder
Last Post: July 24, 2012 (RSS)
By osga - July 23, 2012
Ok... i have this code in the top php code for my page... what should i use at the bottom section of the php code to call the headlines? i.e. =
TOP SECTION:
<?php echo $articlesRecord['content'] ?>
TOP SECTION:
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/var/www/html/osga.com/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
$where = "";
if ($where) {
$where = "categoryNum = '".mysql_escape($articlesRecord['categoryNum'])."' AND num != '".intval($articlesRecord['num'])."'";
}
list($relatedArtilce, $relatedArticlesMetaData) = getRecords(array(
'tableName' => 'articles',
'allowSearch' => false,
'limit' => 5,
'orderBy' => 'createdDate DESC',
'where' => $where,
));
// load records
list($articlesRecords, $articlesMetaData) = getRecords(array(
'tableName' => 'articles',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$articlesRecord = @$articlesRecords[0]; // get first record
// show error message if no matching record is found
if (!$articlesRecord) { dieWith404("Record not found!"); }
?>
Re: [osga] Related Records?
By Jason - July 23, 2012
Hi,
A couple of things here. First, you need to change the order of your code in the top to retrieve related records AFTER you've retrieved your page detail record:
Next, you can output your related records wherever you like, like this:
EXAMPLE:
Hope this helps
A couple of things here. First, you need to change the order of your code in the top to retrieve related records AFTER you've retrieved your page detail record:
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/var/www/html/osga.com/','','../','../../','../../../');
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($articlesRecords, $articlesMetaData) = getRecords(array(
'tableName' => 'articles',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$articlesRecord = @$articlesRecords[0]; // get first record
// show error message if no matching record is found
if (!$articlesRecord) { dieWith404("Record not found!"); }
$where = "";
if ($where) {
$where = "categoryNum = '".mysql_escape($articlesRecord['categoryNum'])."' AND num != '".intval($articlesRecord['num'])."'";
}
list($relatedArticles, $relatedArticlesMetaData) = getRecords(array(
'tableName' => 'articles',
'allowSearch' => false,
'limit' => 5,
'orderBy' => 'createdDate DESC',
'where' => $where,
));
?>
Next, you can output your related records wherever you like, like this:
EXAMPLE:
<h2>Related Articles</h2>
<?php foreach ($relatedArticles as $related): ?>
<a href = "<?php echo $related['_link'];?>"><?php echo $related['title'];?></a><br/>
<?php endif ?>
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/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
By osga - July 24, 2012
as soon as i put in the "call" code... my page went blank... maybe theres a typo somewhere??
Re: [osga] Related Records?
By Jason - July 24, 2012
Hi,
I made some changes to the code on your page that should take care of the issue.
Hope this helps
I made some changes to the code on your page that should take care of the issue.
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/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/