PULLING MATCHING RECORD INFORMATION FROM MORE THAN ONE MULTI-RECORD EDITOR - Aug 3rd, 2010
|
The same client in the above entry upped the ante by then wanting to be able to create as many news articles as desired for any given issue of the newsletter. I had already created a multi-record editor, called “newsletters”, for most of the information that appeared in their newsletters (mastheads, segment titles, meeting information etc.) That meant creating another multi-record editor for the “articles” and being able to have only the correct month’s articles displayed on the detail page.
The first step was to create a simple Multi-Record editor called Newsletter Date with one text field for the Month and Year of their newsletters. These records would be used to populate a pull down list which assigned articles to their correct issue and to create the “past issues” list, and eliminated the chance of misspelling the entries.
The next step was to add a pull down list field to my existing multi-record editor “newsletters” that gets it’s information from the Newsletter Date table, like this.
Field type: list Display as: Pull-down List Options: Get options from Database (advanced) Section Table name : newsletter_date Use this field for option values: month_and_year Use this field for option labels: month_and_year
Then I created a multi record editor for the articles called “newsletter articles”, with the same pull-down list field as above, plus any other fields required, like article headline, article contents, author.
After those editors were created, I created a few test records for an assortment of months, and entered some dummy information into them.
Then it was time to set up a detail page that would display the correct sets of records. After rummaging around in the forum, I found that inserting this where statement in the require once at the top of my page,
'where' => "newsletter_date = '{$newsletter_templateRecord['newsletter_date']}'"
I could restrict the article records displayed to only those that matched the “newsletter_date” field in the original “newsletters” editor.
So this is what the top of my page looked like.
<?php header('Content-type: text/html; charset=utf-8'); ?> <?php require_once "/my_path/cmsAdmin/lib/viewer_functions.php";
list($newsletterRecords, $newsletterMetaData) = getRecords(array( 'tableName' => 'newsletter', 'where' => whereRecordNumberInUrl(1), )); $newsletterRecord = @$newsletterRecords[0]; // get first record list($newsletter_articlesRecords, $newsletter_articlesMetaData) = getRecords(array( 'Table name' => 'newsletter_articles', 'where' => "newsletter_date = '{$newsletterRecord['newsletter_date']}'" )); $newsletter_articlesRecord = @$newsletter_articlesRecords[0]; // get first record ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
The rest of the page was then pretty straight forward.
Since I was always displaying the first record in the “newsletter” table, where I wanted the information from the “newsletter” table to appear I used:
<?php echo $newsletterRecord['my_field_name'] ?>
Where I wanted the Articles to appear I used:
<?php foreach ($newsletter_articlesRecords as $record): ?> <?php echo $record['article_headline'] ?><br /> <?php echo $record['article_contents'] ?><br /> <?php echo $record['author'] ?><br /> <?php endforeach; ?>
And the code for the list of past issues looked like this:
<?php foreach ($newsletterRecords as $record): ?> <a href="<?php echo $record['_link'] ?>"><?php echo $record['newsletter_date'] ?></a> <?php endforeach ?>
I could have set up other multi record editors, and as long as they followed the same pattern, they too would appear correctly.
Hope this approach comes in handy.
|
The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact
Interactive Tools for information on the downloading of the software or the purchasing of licenses.