So, I have a donation table. It stores a $ value and a column box where they choose monetary or in kind donation. in-kind donations can have a $ but usually they don’t. An in-kind donation would be if someone donated a physical item ex, lawnmower, table, chair, so on. I then have donors. Finally, I have a Leadership Giving Group. Based on certain amounts a donor gets put into one of the Leadership Giving Groups. So, for $100 the donor is put in Other Donor group, for $1000 they are put in the next one up and so on. I need to sum all the donations but exclude all in kind donations because those(even if they have a monetary value) don’t count for where to place the donor in the Leadership Group.
TABLES: I wasn’t able to do SHOW CREATE because it has a server value that needs to be changed that I don’t control. I hope this is ok for everyone. I just wanted to show the 3 tables and all their current fields . Sorry for the inconvience.
Ok, so for the tables I couldn’t remember all the syntax but it should be easy enough to see the foreign key and Primary Key and all the fields are there. I just am in a bit of a rush as it is Thanksgiving and my family is mad at me for being on the computer.
CREATE TABLE donor (
DonorID INT NOT NULL AUTO_INCREMENT Primary Key,
FirstName VARCHAR(100),
LastName VARCHAR(100),
Street Address VARCHAR(100),
City VARCHAR(100),
State VARCHAR(2),
Zip VARCHAR(5),
Email VARCHAR(100), );
Restriction is 1 of two entries that they select via drop box. Restricted(then it is been designated by donor for a specific project or Non-Restricted meaning donor doesn’t care how the money is used. DonationType works the same way but it is either In-Kind or Monetary. I want to sum just the monetary values
CREATE TABLE donation (
DonationID INT NOT NULL AUTO_INCREMENT Primary Key,
Restriction VARCHAR(10) NOT NULL,
Amount VARCHAR(100) NOT NULL,
Description VARCHAR(2000),
DonationType VARCHAR(100) NOT NULL,
DonorID INT NOT NULL Foreign Key,
DateReceived DATE NOT NULL,
LeadershipGroup Table: I will add when I get done eating, sorry but my family is about to kill me.
LeaderGrp is not a AI, it is a name of each Leaderhip Group: Other Donor, Founder’s Club, Friend’s Circle, and so on. This will always be unique so I made it the PK but if for some reason and AI field I can do that.
I can post my code if that would make it easier but I feel as though it will turn into a huge wall of text for people. However, this is a website and other programming languages I have used in this project are js and php so if it could be possible in php that is an option as well. I could also give you the link the website and let you view the information because currently it is all made up, obviously the real data can’t be shared if that would be helpful. Just ask for it because I didn’t really want to post it when some people might just go in and start adding data to my tables.
Code:
<?php require_once('header.php') ?>
<!--dont modify above this line-->
<?php
//on ANY page you need to use the database, you need to include the line below ONCE (before doing any db operations)
require_once('connect.php');
function checkAmount($amount, $min, $max)
{
if ($amount >= $min && $amount <= $max)
return true;
else
return false;
}
//array types of users
$founders_club = array();
$headmasters_circle = array();
$dragons_circle = array();
$green_and_white_society = array();
$seventies_society = array();
$millennium_society = array();
$dome_society = array();
$tunnel_society = array();
$friends_circle = array();
$others = array();
// fiscal year
$currentyear = date("Y");
$selectedyear = $_POST["selectedYear"];
if($selectedyear == "")
$selectedyear = $currentyear;
$startdate = $selectedyear . "-07-01";
$enddate = $selectedyear + 1 . "-06-30";
//we need to put all donors inside the dropdown box, this is how to do it
//the actual query
$result = mysql_query("SELECT * FROM donor;") or die (mysql_error());
echo "<h2>Publication List</h>";
echo "<div>Choose Fiscal Year:";
//this will iterate through every record in the resultset and create an option box
echo "<form id=\"fiscal\" action=\"q1.php\" method=\"POST\">
<select name=\"selectedYear\" onchange=\"document.getElementById('fiscal').submit();\">";
for($i=$currentyear; $i >= 2011; $i--)
{
if ($i == $selectedyear)
echo "<option value='".$i."' selected=\"selected\">".$i."</option>";
else
echo "<option value='".$i."'>".$i."</option>";
}
echo "</select></form>";
echo "</div><br>";
//this will iterate through every record in the resultset and create an option box
while($row = mysql_fetch_array($result))
{
$result2 = mysql_query("SELECT SUM(DonationAmount) FROM donations Where DonorID = ".$row['DonorID'] . " and donations.Date_Received BETWEEN '" . $startdate . "' and '" . $enddate . "'" ) or die (mysql_error());
while($row2 = mysql_fetch_array($result2))
{
$amount = $row2['SUM(DonationAmount)'];
if (checkAmount($amount, 50000, 999999))
array_push($founders_club, $row['DisplayName']);
if (checkAmount($amount, 25000, 49999))
array_push($headmasters_circle, $row['DisplayName']);
if (checkAmount($amount, 10000, 24999))
array_push($dragons_circle, $row['DisplayName']);
if (checkAmount($amount, 5000, 9999))
array_push($green_and_white_society, $row['DisplayName']);
if (checkAmount($amount, 2500, 4999))
array_push($seventies_society, $row['DisplayName']);
if (checkAmount($amount, 1000, 2499))
array_push($millennium_society, $row['DisplayName']);
if (checkAmount($amount, 500, 999))
array_push($dome_society, $row['DisplayName']);
if (checkAmount($amount, 250, 499))
array_push($tunnel_society, $row['DisplayName']);
if (checkAmount($amount, 100, 249))
array_push($friends_circle, $row['DisplayName']);
if (checkAmount($amount, -1, 99))
array_push($others, $row['DisplayName']);
}
}
//display results
if(count($founders_club) > 0)
{
echo "<h2>Founder's Club</h2>";
for ($i = 0; $i < count($founders_club); $i++)
echo $founders_club[$i] . "<br>";
}
if(count($headmasters_circle) > 0)
{
echo "<h2>Headmaster's Circle</h2>";
for ($i = 0; $i < count($headmasters_circle); $i++)
echo $headmasters_circle[$i] . "<br>";
}
if(count($dragons_circle) > 0)
{
echo "<h2>Dragon's Circle</h2>";
for ($i = 0; $i < count($dragons_circle); $i++)
echo $dragons_circle[$i] . "<br>";
}
if(count($green_and_white_society) > 0)
{
echo "<h2>Green and White Society</h2>";
for ($i = 0; $i < count($green_and_white_society); $i++)
echo $green_and_white_society[$i] . "<br>";
}
if(count($seventies_society) > 0)
{
echo "<h2>1970's Society</h2>";
for ($i = 0; $i < count($seventies_society); $i++)
echo $seventies_society[$i] . "<br>";
}
if(count($millennium_society) > 0)
{
echo "<h2>Millennium Society</h2>";
for ($i = 0; $i < count($millennium_society); $i++)
echo $millennium_society[$i] . "<br>";
}
if(count($dome_society) > 0)
{
echo "<h2>Dome Society</h2>";
for ($i = 0; $i < count($dome_society); $i++)
echo $dome_society[$i] . "<br>";
}
if(count($tunnel_society) > 0)
{
echo "<h2>Tunnel Society</h2>";
for ($i = 0; $i < count($tunnel_society); $i++)
echo $tunnel_society[$i] . "<br>";
}
if(count($friends_circle) > 0)
{
echo "<h2>Friends' Circle</h2>";
for ($i = 0; $i < count($friends_circle); $i++)
echo $friends_circle[$i] . "<br>";
}
if(count($others) > 0)
{
echo "<h2>Other Donors</h2>";
for ($i = 0; $i < count($others); $i++)
echo $others[$i] . "<br>";
}
?>
<!--dont modify below this line-->
<?php require_once('footer.php') ?>
On a side note, I asked a question yesterday and the response was given to me in this nice little box that showed a table name and all of table column headers. Is there a way I can do that in the question so I can maybe illustrate a little better and make my question clearer?
Thanks everyone,
Joel
If I understand well, the question is : sum all the “not in-kind” donations for every user to determine in which group they should be added.
If so, your DB model lacks some foreign keys in order to link donors to their donations, and to LGGs.
Here’s an example MCD you could use :
Where the MinAmount is the minimum amount needed to belong to this group.
From there, all you have to do is :
You end up with every donor with the amount they donated in real money.