Sub articles. Is it possibile?

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

By mbareara - March 8, 2011

Hi :-)
i'm building my news site starting from am2.

I really appreciate new features of CmsBuilder. It is .... WOW!!!

But i have a problem:

I want to put, in listviewer, and behind each article two or three related articles choosen by author from article list.

I'vre created a field in 'article' table called 'related_article' as list. Label= article Values= num.

Now in the listviewer i would have

ARTICLE 1
><a href="related article title link">related article title</a>

ARTICLE 2
><a href="related article title link">related article title</a>

I know it is impossibile with left join because related article are in the same table...

Any suggestion?
Thank you in advance :-)
Orazio

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: [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/