Woncler Posted February 2, 2013 Share Posted February 2, 2013 Hello, I'm building a house point system for a virtual Hogwarts. I've managed to build up a form that saves its values to MySQL database, and I'm able to display them. The form has three important inputs: group, are the points added or subtracted, and the amount of points. Basically what I'd like to achieve is: When user chooses Group 1, chooses to add points, chooses 5 as the point amount and submits the form, the form itself would save into independent table. But, depending on which group user chose and which action he chose, the point amount would be added (or subtracted) together with existing amount from this group 1, in another table. I hope I explained this clearly So, in brief, is there a way to get a value from database, calculate it with the number that user typed, and update the value? Or is this kind of system too complicated for a total newbie like me? All suggestions and help will be much appreciated! Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 2, 2013 Share Posted February 2, 2013 You are making it more complicated than it needs to be. Simply store the group and point amount change (e.g. 5 or -5) no need to store a separate field to say weather the value is being added or subtracted. Second, there is no need to use these individual records to update records in another table. You can simply get the total for a group/house by doing a query on the table that will sum up all the additions and subtractions. SELECT groupName, SUM(points) AS totalPoints FROM tableName GROUP BY groupName Quote Link to comment Share on other sites More sharing options...
Woncler Posted February 3, 2013 Author Share Posted February 3, 2013 Thanks A LOT! It's now working perfectly! Thank you 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.