Echo details from another section??

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

By gkornbluth - May 27, 2010 - edited: May 28, 2010

Ii Chris,

The plugin has been working perfectly on my detail pages but this is the first time that I've tried to use it on a list page.

On the list page, using the code below, it pulls the venue_name etc., from all the related field records into each event record. (The lookup for the detail page in this set works as expected.)

I know that the inner foreach loop is the culprit, and that I must be missing something simple (as always) but I’m not having any luck figuring it out.

The lookup is from a single value list field.

Thanks,

Jerry Kornbluth

Here’s the code at the head of the list page:

list($e_blast_events_noticeRecords, $e_blast_events_noticeMetaData) = getRecords(array(
'tableName' => 'e_blast_events_notice',
));

beta_lookupRelatedFields(array(
'table' => 'e_blast_events_notice',
'recordList' => &$e_blast_events_noticeRecords,
'fieldList' => array( 'venue' )
));

$e_blast_events_noticeRecord = @$e_blast_events_noticeRecords[0]; // get first record


And here’s the code I;m using to display the information

<?php foreach ($e_blast_events_noticeRecords as $record): ?>
<?php if ($record['event_title']): ?><br /><br />

<?php foreach ($e_blast_events_noticeRecords as $record): ?>

<?php $venue = $record['venue']; ?>

Location:</span><br />
<?php echo $venue['venue_name']; ?><br />
<?php echo $venue['venue_address'] ?><br />
<?php endforeach; ?>
<?php endforeach; ?>
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

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

By Jason - May 31, 2010

Hi Jerry,

I've been looking over this. So the problem is that for each event displayed, it's displaying all related records, not just the related record specific to that event. Is that right?

If so, I think you won't need your inner foreach loop. It looks like what's happening is that for each event, you have a second loop displaying all the venue names of each event.

Try this code instead:

<?php foreach ($e_blast_events_noticeRecords as $record): ?>
<?php if ($record['event_title']): ?><br /><br />

<?php $venue = $record['venue']; ?>

Location:</span><br />
<?php echo $venue['venue_name']; ?><br />
<?php echo $venue['venue_address'] ?><br />
<?php endforeach; ?>


Hope this helps.
---------------------------------------------------
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: [gkornbluth] Echo details from another section??

By Jason - May 31, 2010

Hi Jerry,

If you could email me CMS and FTP login details to jason@interactivetools.com, I can take a closer look.

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/

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

By gkornbluth - May 31, 2010

Sure,

Thanks much for this,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

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

By Jason - May 31, 2010

Hi Jerry,

Since you're only returning one record, there is no need for a foreach loop at all. This code should work better:

<?php $venue = $e_blast_events_noticeRecord['venue']; ?>


Location:</span><br />
<?php echo $venue['venue_name']; ?><br />
<?php echo $venue['venue_address'] ?><br />


Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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