Hello All,
I’m building a project that involves a 7 tiered affiliate program and I’m trying to wrap my head around displaying this downline of affiliates to the members. I’m using object oriented code with a common functions include page.
No problems in creating a members “frontline”, and showing the entire downline in a tree view seems to be a simple re-iteration of this same code. It’s the recursion factor that’s killing me.
If someone could give me some help on this I would certainly appreciate it.
Here’s what I have to create a members “frontline” affiliates:
[code] //--------------------------------------------------------------------------
function ocd_list ()
{
$this->mainTemplate = “./templates/downline.tpl”;
$this->pageTitle = “My Downline”;
$this->pageHeader = “My Downline”;
$siteURL = $this->db->GetOne (“Select value From settings Where keyname=‘SiteUrl’”);
$total = $this->db->GetOne (“Select Count(*) From members
Where referrer_id=’{$this->member_id}’ And member_id!=’{$this->member_id}’”);
$username = $this->db->GetOne (“Select username From members
Where member_id=’{$this->member_id}’”);
$this->data = array (
"MAIN_HEADER" => $this->pageHeader,
"HEAD_LEVEL" => "<b>Level</b>",
"HEAD_USERNAME" => "<b>ID</b>",
"HEAD_NAME" => "<b>Name</b>",
"HEAD_MEM_TYPE" => "<b>Title</b>",
"HEAD_PV" => "<b>PV</b>",
"HEAD_GV" => "<b>GV</b>",
"HEAD_JOINED" => "<b>Join Date</b>",
"MAIN_REFLINK" => $siteURL . "?ref=" . $this->member_id,
"MAIN_PROFLINK" => $siteURL . "$username",
);
$bgcolor = "";
if ($total > 0)
{
$result = $this->db->ExecuteSql ("Select * From members Where referrer_id='{$this->member_id}' Order By {$this->orderBy} {$this->orderDir}");
for ($i = 0; $i < $total; $i++)
{
$row = $this->db->FetchInArray ($result);
$id = $row['member_id'];
$lev = $i+1;
$mem_id = $row['member_id'];
$username = $row['username'];
$name = $row['first_name'] . " " . $row['last_name'];
$level = $row['level_id'];
$type = $this->db->GetOne ("Select `title` From `levels` Where level_id='$level'");
$pv = "";
$gv = "";
$reg_date = date ("F d, Y", $row['reg_date']);
$bgcolor = ($bgcolor == "") ? "#E7E7E7" : "";
$this->data ['TABLE_ROW'][] = array (
"ROW_LEVEL" => "$lev",
"ROW_USERNAME" => $username,
"ROW_NAME" => $name,
"ROW_MEM_TYPE" => $type,
"ROW_PV" => $pv,
"ROW_GV" => $gv,
"ROW_JOINED" => $reg_date,
"ROW_BGCOLOR" => $bgcolor,
);
}
$this->db->FreeSqlResult ($result);
}
else
{
$bgcolor = ($bgcolor == "") ? "#E7E7E7" : "";
$this->data ['TABLE_EMPTY'][] = array (
"ROW_BGCOLOR" => $bgcolor
);
}
}
}[/code]
I know this needs a recursive foreach loop, or perhaps a couple of them, but not sure where to put them, or how to integrate them into the functions.
Thanks a bunch.
Josh