Reputation: 53
I have a php form and on submit, I want the data to be sent to a table. After a successful entry, I then want to add up all the values (numerical) from a column that share the same email address in the first column (the value is the 3rd column) and then submit that total to a different table. Is this even possible? I am using MySQL and PHP.
For example:
EMAIL(COL1) COL2 COL3
[email protected] (data) 10
[email protected] (data) 10
[email protected] (data) 10
COL3 TOTAL: 30
Submit 30 into new table with email address from COL1
Upvotes: 1
Views: 47
Reputation: 628
I would just make a VIEW.
CREATE VIEW total
AS SELECT email
, SUM(col3
) FROM table
GROUP BY 1.
You could do this with triggers in MySQL or via PHP, but for this sort of simple operation a VIEW is probably most reliable and easiest.
Upvotes: 0
Reputation: 942
You may consider adding a trigger to your MySQL database. A trigger is a named database object that is associated with a table, and that activates when a particular event occurs for the table.
Upvotes: 2