I am trying to code a script that takes database entries like these:
╔════╦═════════╦════════╦══════════╗
║ id ║ user_id ║ action ║ time ║
╠════╬═════════╬════════╬══════════╣
║ 1 ║ 1 ║ 1 ║ 12:00:00 ║
║ 2 ║ 1 ║ 2 ║ 12:10:00 ║
║ 3 ║ 1 ║ 1 ║ 18:00:00 ║
║ 4 ║ 1 ║ 2 ║ 18:10:00 ║
╚════╩═════════╩════════╩══════════╝
Then works out the difference between the two actions 1 & 2 and then sum them together, this example would make a total of 20:00
I don't really know where to start for this and can't seem to find anything on the net that helps.
If someone could point me in the right direction, or any help will be greatly appreciated.
Edit: Other actions may be in the database (1-7), as well as multiple users.
Edit2: More complex example table beneath, still should result in the same example of 20:00
╔════╦═════════╦════════╦══════════╗
║ id ║ user_id ║ action ║ time ║
╠════╬═════════╬════════╬══════════╣
║ 1 ║ 1 ║ 1 ║ 12:00:00 ║
║ 2 ║ 1 ║ 2 ║ 12:10:00 ║
║ 3 ║ 2 ║ 1 ║ 12:30:00 ║
║ 4 ║ 2 ║ 2 ║ 12:40:00 ║
║ 5 ║ 2 ║ 3 ║ 12:50:00 ║
║ 6 ║ 2 ║ 4 ║ 13:00:00 ║
║ 7 ║ 3 ║ 1 ║ 14:00:00 ║
║ 8 ║ 3 ║ 2 ║ 14:10:00 ║
║ 9 ║ 1 ║ 1 ║ 18:00:00 ║
║ 10 ║ 1 ║ 2 ║ 18:10:00 ║
╚════╩═════════╩════════╩══════════╝