Jump to content

Gathering data together via mulitple tables and find SUM


beanymanuk

Recommended Posts

Hi

 

I am trying to find out the total value of dontations raised per email address but in order to find this information I have to do a few queries in order to find out the email address by using there ID and also need to see what percentage of each donation and which cause this donation went to.

 

Find out donation amount

SELECT wp_supporters_donations.SFMemberNumber, wp_supporters_donations.KickbackAmount 
FROM supporter_2_cause RIGHT JOIN wp_supporters_donations 
ON supporter_2_cause.supp_id=wp_supporters_donations.SFMemberNumber 
GROUP BY wp_supporters_donations.SFMemberNumber	

 

Find out percentage here

function getdonationperc($supp_id, $causeid, $ProcessDate){
global $wpdb;
$fu=0;
$ProcessDate = substr($ProcessDate, 0, 6);

//echo $ProcessDate;
//echo $supp_id." ";
//echo $causeid;
$new = $wpdb->get_results("SELECT * FROM dp_log WHERE sid=$supp_id AND cid=$causeid AND date=$ProcessDate AND fp != 'yes' ORDER BY id LIMIT 0, 1");
foreach ($new as $new){
$fu = $new->perc;
//echo $fu;
}
//echo "  RESULT11 ".$fu;

if($fu=="0" || $fu==NULL){
	$newresult = $wpdb->get_results("SELECT * FROM supporter_2_cause WHERE supp_id=$supp_id AND caus_id=$causeid AND deleted!='1' AND fp!='yes' ORDER BY id LIMIT 0, 1");
	foreach ($newresult as $newresult){
		$fu = $newresult->donation;
				//echo "wtf";
	}
	//echo $fu;
	if($newresult == NULL) {
	$fu="0";
	}
}else{
	//$fu="0";
}
//echo $supp_id." - ".$causeid." - ".$ProcessDate." - ".$fu."<br/>";
//echo "  RESULT ".$fu;
return $fu;
}

 

Find out email address attached to each donation

SELECT email FROM supporters WHERE id='SFMemberNumber' 

 

Then I need to add all donations up for each email address per each cause and output these / insert into a new table.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.