Define new variable created by FOREACH

7 posts by 3 authors in: Forums > CMS Builder
Last Post: April 1, 2009   (RSS)

Re: [rjbathgate] Define new variable created by FOREACH

By Dave - March 31, 2009

Hi Rob,

Try this:

$recipients = '';
foreach ($contactsRecords as $record) {
$recipients .= $record['email_address'] . ', ';
}
$recipients = rtirm($recipients, ', '); // remove trailing comma and space


Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Define new variable created by FOREACH

Hi Dave,

Cheers for that... I receive the error:


Fatal error: Call to undefined function rtirm() in /home/hartford/public_html/cmsAdmin/lib/menus/search-results.php on line 136

Line 136 is:

$recipients = rtirm($recipients, ', '); // remove trailing comma and space

Any ideas?
Cheers
Rob

Re: [rjbathgate] Define new variable created by FOREACH

Got it:

<?php
$allemails = '';
$firstEntry = true;
foreach($contactsRecords as $record){
if(!$firstEntry){
$allemails .= ', ';
}
else{
$firstEntry = false;
}
$allemails .= $record['email_address_1'];
}
?>


Note, variable in that code is $allemails as oppose to $recipients, but hey, same thing...

Re: [rjbathgate] Define new variable created by FOREACH

By ross - April 1, 2009

Hi there.

Just wanted to make sure that last post meant you got things going :). Let me know if you still need a hand.

Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [rjbathgate] Define new variable created by FOREACH

By Dave - April 1, 2009

Glad to hear it's working.

Sorry about the typo, I meant to type rtrim(). Here's the docs for it for next time so you can have one more tool in your toolbox: http://www.php.net/rtrim

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Define new variable created by FOREACH

By rjbathgate - April 1, 2009

Hey,

Yeah got it working cheers...

I didn't even notice the type rtirm -- knew it was rtrim, I even read it as rtrim!!

Cheers all
Rob