Forum Moderators: coopster
Now the problem occurs when I try to calculate average business of all the 2000+ agents at a time. The whole page crashes while retrieving them.
Here is the code:
function getAdminLeaders($parent,$startdate, $enddate, $paid,$teamtype,$type='sub', $av=0)
{
$arr = array();
$ids = //fetch id,name, title and parentID alongwith the business from the database which involves the join query between two tables(agents and business tables)
for($i=0,$j=sizeof($ids);$i<$j;$i++)
{
$arr1 = array();
$arr1['title'] = $ids[$i]['title'];
$arr1['name'] = $ids[$i]['name'];
$arr1['upline'] = getAgentNameTitle($id[$i]['parentID']);
$arr1['personal'] = getRawProduction($id[$i]['ID'], $startdate, $enddate, $paid, 'personal');
$arr1['gross'] = getRawProduction($id[$i]['ID'], $startdate, $enddate, $paid, $teamtype);
if($av==1)
$arr1 = getAV($id[$i]['ID'],$type,$paid,$startdate, $enddate,$arr1);
$arr[$id[$i]['ID']] = $arr1;
}
return $arr;
}
Functions used in above code explained:
1. getAgentNameTitle - retrieves name and designation of the parent agent.
2. getRawProduction - gets the personal business or business made by the downline agents of a particular agents. It involves a two join statements involving three tables alongwith UNION. Its the only way I could get all the downline agents according to their team types.
3. getAV - gets the average business of the individual which itself requires its own loop while getting the downline agents businesses. Actually it applies a special set of calculations which can't be modifiable.
Here you may see that while retrieving all the agents, I have to call 4 different functions for the individual agents. I think there may be some way to optimize it so that its become faster. Really going insane on optimizing it.
Please help!
Thanks in advance.
foreach ($ids as $key => $data) {
$arr1 = array();
$arr1['title'] = $data['title'];
$arr1['name'] = $data['name'];
$arr1['upline'] = getAgentNameTitle($data['parentID']);
$arr1['personal'] = getRawProduction($data['ID'], $startdate, $enddate, $paid, 'personal');
$arr1['gross'] = getRawProduction($data['ID'], $startdate, $enddate, $paid, $teamtype);
if($av==1)
$arr1 = getAV($data['ID'],$type,$paid,$startdate, $enddate,$arr1);
$arr[$data['ID']] = $arr1;
}
return $arr;
}
}
Do you get a timeout error page when you try and run the page?