beanymanuk Posted January 4, 2012 Share Posted January 4, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/254354-gathering-data-together-via-mulitple-tables-and-find-sum/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.