Sub articles. Is it possibile?

4 posts by 2 authors in: Forums > CMS Builder
Last Post: March 14, 2011   (RSS)

Re: [orazio] Sub articles. Is it possibile?

By Jason - March 8, 2011

Hi Orazio,

I'm assuming related_article field is a multi-value list. Is that right?

Multi-value fields store values as a string separated by tab characters (\t). We for each record, we can get this list and then use it to do another query to the database to get related articles. Try something like this:

<?php

$relatedArticleNums = join( ",", explode( "\t", trim( $record['related_articles'], "\t" ) ) );
if(!$relatedArticleNums){ $relatedArticleNums = "0"; }

list( $relatedArticles, $realtedArticlesMetaData ) = getRecords( array(
'tableName' => 'articles',
'allowSearch' => false,
'where' => "num IN ($relatedArticleNums)",
) );

?>


You can use this for each article you're outputting to get related articles.

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/

Re: [Jason] Sub articles. Is it possibile?

By mbareara - March 12, 2011

Sorry but i don't understand...

I made this

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/siciliatoday/','','../','../../','../../../');
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($articoliRecords, $articoliMetaData) = getRecords(array(
'tableName' => 'articoli',
'leftJoin' => array(
'category' => 'categoria',
),
));

$relatedArticleNums = join( ",", explode( "\t", trim( $record['articoli_correlati_1'], "\t" ) ) );
if(!$relatedArticleNums){ $relatedArticleNums = "0"; }

list( $relatedArticles, $relatedArticlesMetaData ) = getRecords( array(
'tableName' => 'articoli',
'allowSearch' => false,
'where' => "num IN ($relatedArticleNums)",
) );



?>

But it gives me an erorr server...

Re: [orazio] Sub articles. Is it possibile?

By Jason - March 14, 2011

Hi,

You need to do the query that selects the related articles while you're outputting your first set of articles.

If you could attach the .php file you're working with, I can help give you a better example.

Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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