Echo details from another section??

36 posts by 5 authors in: Forums > CMS Builder
Last Post: May 31, 2010   (RSS)

Re: [jonoc73] Echo details from another section??

By Kenny - September 29, 2009

Just simply add to your top of page code. Here are three example viewers on one page:

<?php require_once "/home/XXXXXX/public_html/webadmin/lib/viewer_functions.php";

list($header_graphicsRecords, $header_graphicsMetaData) = getRecords(array(
'tableName' => 'header_graphics',
'limit' => '1',
'orderBy' => 'RAND()',
'allowSearch' => '0',
));

list($metatagsRecords, $metatagsMetaData) = getRecords(array(
'tableName' => 'metatags',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$metatagsRecord = @$metatagsRecords[0]; // get first record

list($unitsRecords, $unitsMetaData) = getRecords(array(
'tableName' => 'units',
'where' => 'status LIKE "%sale%"',
));


?>


Then just add your "<?php echo $guided_tourRecord['tour_level'] ?>" line wherever you need it on that page.


Kenny

Re: [sagentic] Echo details from another section??

By (Deleted User) - September 30, 2009

Thanks for this. I have used the middle one of your three examples and it works great.

I have a bunch of staff profiles in the staff_profiles section. Each staff member has name (name), phone number (staff_phone), email (staff_email).

What would I use instead of <?php echo $guided_tourRecord['tour_level'] ?> to get that data on another page.

Say I wanted all three (name, phone and email) for 4 members of staff to be displayed on a different page?

It may well be one of the items you listed but I can't figure out which one. Any help would be much appreciated as I know once I 'get it' I'll be off and all the pages will be cross populated...

Thanks Jono

Re: [jonoc73] Echo details from another section??

By Kenny - September 30, 2009

Actually that's just ONE example of how you put THREE viewers on the same page.

Use your code generator to place the code on your page. You can add as many sections (viewers) on your page as you would like. You just don't have to add the same code more than once.

My example is for my sections. You'll have to use your code instead.

I hope that makes sense.


Kenny

Re: [sagentic] Echo details from another section??

By (Deleted User) - September 30, 2009

Kenny,

I have looked at the code from the generator and I think it gets the code from one record number in url. For example post 3.

I'm afraid I'm still new to CMS Builder so you'll have to bear with me...

How would I get the name (Field name: staff_name) from say the staff member with url number 4 and then get say a phone number (Field name: staff_phone) from a different staff member with the url number of 2?

Thanks for your help so far.
Jono

Re: [jonoc73] Echo details from another section??

By Kenny - September 30, 2009

You have lost me on this one a bit.

You'll need to create two pages - one is a list page and the other is a viewer page. Linking from the list page to the viewer page using the generated code will pull up the associated record and display it.

For example, this page is a list page:
http://demo2.interactivetools.com/cmsbuilder/demosite/news.php

And the page the articles link to is the detail page:
http://demo2.interactivetools.com/cmsbuilder/demosite/newsDetail.php?Lorem-ipsum-tempus-eu-gravida-quis-5

Notice the number 5 at the end of the URL? That's because it is the 5th record in that table in the database. (Record Number)


Calling a specific record number can be done in a variety of ways. Try some of the ways listed here: http://www.interactivetools.com/docs/cmsbuilder/viewer_search.html


I hope that helps, but in any case let us know.

Kenny

Re: [sagentic] Echo details from another section??

By (Deleted User) - September 30, 2009

Sorry, I just read my previous post back and it lost me too!

I have a page about a holiday tour. It is a multi-record page.

On that page I have all sorts of content pulled from the holiday tour section - easy.

Also within the page I want to include the guides available and their names, telephone details etc - this data would be pulled from the different staff section.

Depending on what is selected within the holiday tour page editor using a load of if statements the selected guides show up on the holiday tour page.

So for example, I am compiling the holiday tour and tick the boxes next to Bill and also Bob and save.

The holiday page is displayed and in the page it also includes the name and phone numbers of both Bill and Bob. If Bob isn't ticked when making the tour he isn't displayed.

Sorry if this is so confusing - it's difficult to explain.

Thanks
Jono

Re: [jonoc73] Echo details from another section??

By Chris - September 30, 2009

Hi Jono,

Okay, let me see if I've got this right...

You have a multi-value list field called "guides" in your "guided_tours" section. Based upon what is selected in that list field, you want to display certain fields from related records in another section.

Is this correct? Also, what is the name of the other section?
All the best,
Chris

Re: [chris] Echo details from another section??

By (Deleted User) - October 1, 2009

Hi Chris,

I have a multi-value section called "staff_profiles".

In this section I have say three fields I would want to use elsewhere on the site, "title", "staff_email" and "staff_phone".

I then have another multi-value section called "guided_tours".

Based upon which staff member is ticked in a list field called "guides" I would like to display their "title", "staff_email" and "staff_phone" fields contents.

It's basically the ability to pull field data from a certain staff section and put it across the site in various if statements.

Jono

Re: [jonoc73] Echo details from another section??

By Chris - October 1, 2009 - edited: October 1, 2009

Hi Jono,

Those are "multi record" sections. The term "multi value" refers to List fields which are able to store multiple answers (as we'll be using below.)

I've been working on a plugin which makes the process of looking up related records on viewer pages a lot easier. It's attached to this post and there are instructions on how to set it up below.

We're going to get rid of those if statements, replacing them with a simpler and more maintainable system.

Step 1: First off, let's make sure your "guides" field is set up correctly.

Field Label: Guides
Field Name: guides
Field Type: list

Field Options:
Display As: checkboxes (multi value)
List Options: Get options from database (advanced)
Section Tablename: staff_profiles
Use this field for option values: num
Use this field for option labels: staff_email


If you had to change it, you'll likely need to edit any existing guided_tours records and re-enter their "guides" choices. If you wish, you can safely change the "Use this field for option labels" option later without having to fix anything.

Step 2: Install the Related Record Lookup Functions Plugin attached to this post. This will make Step 3 a lot simpler. Upload the file to your server in the /cmsAdmin/plugins directory, then log into CMSB, go to Admin > Plugins, and click Activate on it.

Step 3: Finally, we'll set up your Viewer. You'll need to add some code to the top of your page. You probably already have the code in black in your PHP source code; add the code in blue below it:

list($guided_toursRecords, $guided_toursMetaData) = getRecords(array(
'tableName' => 'guided_tours',
));

beta_lookupRelatedFields(array(
'table' => 'guided_tours',
'recordList' => &$guided_toursRecords,
'fieldList' => array( 'guides' )
));


That code will change your $record['guides'] from a tab-separated list of numbers into a list of the correct records from the staff_profiles section. To display them, you'll need to "foreach" over them. For example:

<?php if (empty($record['guides'])): ?>
No guides.
<?php else: ?>
Guides:
<ul>
<?php foreach ($record['guides'] as $staff): ?>
<li>
<?php echo $staff['title'] ?>
<?php echo $staff['staff_email'] ?>
<?php echo $staff['staff_phone'] ?>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>


I hope this helps! Please let me know if you have any questions or run into any problems.
All the best,
Chris