So every member has an intro_id, which stands for the userid of the guy who referred the member. If member 2 was referred by member 1, member 2s intro_id would be 1.
I am basically trying to "count" every ref, multiple levels deep. First level are direct referrals, second level are referrals referred by the first level refs.
Code so far:
function countReferrals($userid, $i){
if($userid=='')
{
$userid=$_SESSION['member_id'];
}
if($i=='' || empty($i))
{
$i=0;
}
$query1 = new Bin_Query();
$sql = "select member_id from members where intro_id='".$userid."'";
$query1->executeQuery($sql);
$level1Refs = $query1->records;
foreach($level1Refs as $refer)
{
$i=$i+1;
echo "<script>console.log( 'Debug Objects | countReferrals | \$i = ".$i." | \$refer[member_id] = ".$refer['member_id']." ' );</script>";
self::countReferrals($refer['member_id'], $i);
}
}
This maximum output number ($i) is around 150. Sometimes 149, 146, ... First level referrals are 400+ and some in second level. So it's clearly stopping before it counts every ref, but why?
If I remove
self::countReferrals($refer['member_id'], $i);
It counts all level 1 refs. But I want refs from the other levels, too.