Followup on extracting information from a text field and inserting it into another field

5 posts by 2 authors in: Forums > CMS Builder
Last Post: November 29, 2013   (RSS)

By gkornbluth - November 27, 2013

Hi All,

I don’t know who is still subscribed to post # 79134 http://www.interactivetools.com/forum/forum-posts.php?extracting-an-email-address-from-a-text-field-79134 so I decided to re-post a followup question.

THEN
In that post, I was extracting an email address from a text field and inserting it into an email field if the email field was blank.


NOW
I’m now trying to locate the word “free” in that text field, and if it exists, insert the option value “2" into a list field called "membership_level".

The basic concept seems to be working (too well).

THE ISSUE
My problem is that the code below inserts the option value “2" in all blank membership_level fields and I only want it to insert a "2" in the memberhip_level field if the membership field is currently blank AND the target word $myword exists in internal_notes.

I tried to include the parameter || $allLevel == '' in the if statement, but that didn’t seem to do the job.

I hope someone can see my error.

Thanks,

Jerry Kornbluth

 <?php
function extract_membership_level_from($string){
    $myword = 'free' ;
    preg_match_all("/\b" . $myword . "\b/i", $string, $matches);
    return $matches[0];
}
    ?>
      
  <?php
  foreach ($accountsRecords as $record) {
    $allLevel  = extract_membership_level_from( $record['internal_notes'] );
    if ($record['membership_level'] || @$allLevel == '' ) { continue; } // skip records that already have a membership level set (or where there’s no match for $myword in internal_notes )
    $firstLevel = '2';
    print "User {$record['username']} will get this level: $firstLevel<br/>\n";
   mysql_update('accounts', $record['num'], null, array('membership_level' => $firstLevel ));
 }
?>

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

By gkornbluth - November 28, 2013

Thank you Daryl,

I'm in the middle of our families annual Turkey devouring ritual, but I'll jump on this first thing tomorrow and let you know what happens.

I have a feeling you're much too modest and that your suggestion will work superbly.

Best,

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

By gkornbluth - November 29, 2013

Hi Daryl,

That small change seems to have made all the difference.

More testing required so I don't mess anything else up, but  I think it's a winner.

Thanks again,

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

By gkornbluth - November 29, 2013

Perfect Solution!!

Thank you again.

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