We are implementing a new feature in our club, we already have a coded infinity bonus, we want to implement a traditional coded infinity bonus to compliment it.

Once a club member achieves a rank then after that date all new people referred into their club's organization is 'coded' to them for bonus over rides on everything that club member purchases. However, their other organziation does not get coded to them. We want to now change that to where once they achieve that rank then everyone they ever referred from the timestamp their account was created and on, including everyone the people they referred and so on, unlimited levels down to be coded to them in a different field so we can give them a bonus on their whole organization in addition to just the ones that come in after they get ranked.

I seem to be having a problem updating the second fields.

One of our club Members has referred 1016 people personally. It seems to update only 111 of those people, no matter what I try.

Here is what I did, can you tell me what I did wrong?

my $_countLevels = 0; my $_countRank1 = 0; my $_countRank2 = 0; my $_countAllNewlyAdded = 0; my $_countAllNewlyAddedFailures = 0; my $_highLevel = 0; my $_dbi_errors = ""; my $sth = $dbh->prepare(qq{select * from `registered_users` where `ran +ked1` = "1"}); $sth->execute(); while(my $_regu = $sth->fetchrow_hashref()) { $_countRank1++; &buildTradRank($_regu->{MemberId},$_regu->{MemberId},'rank1',0); } $sth->finish(); $sth = $dbh->prepare(qq{select * from `registered_users` where `ranked +2` = "1"}); $sth->execute(); while(my $_regu = $sth->fetchrow_hashref()) { $_countRank2++; &buildTradRank($_regu->{MemberId},$_regu->{MemberId},'rank2',0); } $sth->finish(); sub buildTradRank { ($_rankedid,$_startingid,$_rank,$_level); my $_fieldName = $_rank . '_traditional'; $_level++; $_countLevels++; $_highLevel = $_level if $_level > $_highLevel; # Once we reach someone else ranked, stop there do not go no furth +er since that person will get all their organization coded to them la +ter if($_level == 1) {# since this is their personal referrals make su +re they are all coded to them even if they are ranked... my $_addToSearch = ""; } else {# Now make sure it does not select anyone that is also ran +ked at this level my $_addToSearch = qq~ and `$_rank` = "0"~; } my $sth2 = $dbh->prepare(qq{select * from `registered_users` where + `referrer_id` = ?$_addToSearch}); $sth2->execute($_startingid); while($_nregu = $sth2->fetchrow_hashref()) { if(!$_nregu->{$_fieldName} || ($_nregu->{$_fieldName} && $_nre +gu->{$_fieldName} != $_rankedid)) { my $_updated = $dbh->do(qq{update `registered_users` set ` +$_fieldName` = ? where `MemberId` = ?}, undef, $_rankedid, $_nregu->{ +MemberId}); if($_updated) { $_countAllNewlyAdded++; } else { $_countAllNewlyAddedFailures++; $_dbi_errors .= $DBI::errstr . "\n" if $DBI::errstr; } } if(!$_nregu->{$_rank}) {# This person not ranked so add their +referred club members to this persons array # Has this person referred anyone? my $_countReferred = $dbh->selectrow_array(qq{select count +(*) from `registered_users` where `referrer_id` = ? and `$_rank` = "0 +"}, undef, $_nregu->{MemberId}); if(!$_countReferred) { next; # Had no referrals so just go to the next person +... } # If made it here then this person had referrals so go wor +k on their referrals... &buildTradRank($_rankedid,$_nregu->{MemberId},$_rank,$_lev +el); } next; } return 1; }
That should climb down the trees of each person registered. I don't see any problems so can you point any out? I removed the finish() call in the subroutine in case that was killing all instances of the database call in the prepare statement...

Thanks in advance for any help you can offer.

Thank you very much Rich

In reply to Recursive programming question by ukndoit

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.