Ninjakreborn Posted December 14, 2006 Share Posted December 14, 2006 This is related to php, but more of math.I have a donation list.When one is deleted it's updating a monetary value, by removing it from that value, which is subtraction, when it adds one, it takes the value, and adds the amount on the donation to it.I don't know what do to when they edit the donaiton, adding, or just subtracting won't work, what process should I use.Basically I have 1 monetary value, say 500.00If a new donation is added which is 250.00 it adds 250.00 to the 500.00 which is 750.00easy, just addingwhat if it's then deleted, ok that's fine just 750 -250.00 = 500.00done, but say it's added 250.00Later they want to edit that, to they change it to 240, or 360 or something, I can;t just add this new number to the total, or subtract it, it won't turn out correct, so how do I correctly edit the total with the new value, without miscalculation? Quote Link to comment Share on other sites More sharing options...
obsidian Posted December 14, 2006 Share Posted December 14, 2006 My first question: do you have anywhere that you are storing the individual donations? If not, you should. This would easily allow them to add, delete or edit a donation, and all you have to do is run a SUM() query on the amount of all your donations to get your total.Another thought: why on earth are people being allowed to edit or delete a donation? Isn't that sort of bad business practice? Just curious... Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted December 14, 2006 Author Share Posted December 14, 2006 "in case of wrong input etc" is that he just said, he's on msn.See I have each donation stored in the database yes, the delete was fine, I pulled the information, and when they delete I subtract. It's a little more involved, because it also goes on category, but I ahve all that programmed, it's just the math to do the editing itself. Even the total is fine, so far I just add them all up, adn the total is done. I just need to figure out how to handle the editing situation with math?When they add one, it tells what category, adds the donation to teh category amount, then updates the total, and full balance, no problemSame with deleting, it subtracts it, adds up total, works up balance. No problem, but the deleting has me stumped, since straight add or subtract won't work. Quote Link to comment Share on other sites More sharing options...
Philip Posted December 14, 2006 Share Posted December 14, 2006 What if you when they removed they are not deleted, but rather brought up in a negative number. Same thing with editing.Example:$500 deposit from person A$240 deposit from person B *Person A changes mind**Person B wants to subtract $10 for beer*So your table would look like:Amount | Person | Reason$500 A $240 B -$500 A N/A-$10 B Beer Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted December 14, 2006 Author Share Posted December 14, 2006 I am a little confused with what you mean, with this,w hen they delete it's a little different. Once the donations are made theycan't be changed by the person, but it's just there for incase they made mistakes. The numbers can go negative, there is a lot of math here so far. THe structure's already done, it's just on editing, I am confused on what to do calculation wise. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted December 14, 2006 Author Share Posted December 14, 2006 I think it would work like this.Stored value = 500.00Current total = 1000.00New edited value = 450.00Database workPull stored valuesubtract stored value from totaltake add editid value back to totalso you have1000 - 500.00 = 500.00Then you add back in the new edited value 500 + 450 = 950.00that is the new total, I think that will work each time, won't it. Quote Link to comment Share on other sites More sharing options...
obsidian Posted December 14, 2006 Share Posted December 14, 2006 Basically, take the value from [b]after[/b] the edit and subtract the value from [b]before[/b] the edit. Then, you take that value and add it to the total. With that pattern, if they [i]subtract[/i] from their original donation, you come up with a negative number that will appropriately modify the grand total down.Make sense? Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted December 14, 2006 Author Share Posted December 14, 2006 Yes that makes sense, either one of these way may work, I will play with them both, or put up 2 test scenarios, to check the math on both.Thanks guys Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted December 14, 2006 Share Posted December 14, 2006 i'm with obsidian's first post with this one. if someone donates, they donate cos they want to - not because they need or will use some sort of money-back guarantee, so that takes away having to deduct.as for additions - keep additional donations seperate. why would they/you need to adjust it? if i make a mistake using paypal to donate £50 instead of £5, then I do believe that it's down to the recipient to refund me if they so choose. but there's enough 'please confirm' to make sure that i dont do something stupid.once you've got a list of donations (with no negative ones) then you just do what obsidian said and tot them all up.am I missing something? Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted December 14, 2006 Author Share Posted December 14, 2006 Hmm thanks, that should solve a few of my problems, and make the other mathematics a little safer, with less chances of messing up.Thanks red, and obsidian. Quote Link to comment 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.