$pq=mysql_query("SELECT * FROM fundraising_campaigns_users_link WHERE fundraising_campaigns_id='$r->id'");
while($pr=mysql_fetch_object($pq)){
$u=user_load_by_uid($pr->users_uid);
//hopefully this never returns false, but who knows..
if($u){
//we only want the primaries, yea, i know... we have this werid confusing between a USER being linked to a sponsor and then a sponsor having multiple users
//and then only getting the primary contact for the sponsor even if it might not be the user thats in teh campaign... my brain hurts
// if($u['primary']=="no")
// continue;
//gah i dont know what the heck to do here
if($u['sponsors_id']){
$cq=mysql_query("SELECT SUM(value) AS total FROM fundraising_donations WHERE sponsors_id='{$u['sponsors_id']}' AND fundraising_campaigns_id='$r->id' AND status='received' AND fiscalyear='$thisyear'");
$cr=mysql_fetch_object($cq);
$thisappeal=$cr->total;
$cq=mysql_query("SELECT SUM(value) AS total FROM fundraising_donations WHERE sponsors_id='{$u['sponsors_id']}' AND status='received' AND fiscalyear='$thisyear'");
$cr=mysql_fetch_object($cq);
$thisyeartotal=$cr->total;
$cq=mysql_query("SELECT SUM(value) AS total FROM fundraising_donations WHERE sponsors_id='{$u['sponsors_id']}' AND status='received' AND fiscalyear='$lastyear'");
$table['header']=array("Appeal Name","Target","Received","% to Budget","# of Prospects","# of Donors/Sponsors","Rate of Response","Average Amount Given");