Re: [jonoc73] Echo details from another section??
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