So I have a MySQL table that looks something like this:
id timestamp action timePassed
1 2012-07-10 22:44:00 start 0
2 2012-07-10 22:44:50 pause 50
3 2012-07-10 22:45:30 play 50
4 2012-07-10 22:47:25 pause 205
5 2012-07-10 22:48:05 play 205
I don’t know how obvious it is but what’s happening here is basically on every ‘pause’ row I am calculating the difference in seconds between the current timestamp and the timestamp of the ‘start’ row.
The only way I can think of doing this is to INSERT a new ‘pause’ row into the database so the timestamp is generated…then query the database for the timestamp of that ‘pause’ row…calculate the difference in seconds between that ‘pause’ row and the ‘start’ row using PHP…then UPDATE the ‘pause’ row with the timePassed result.
My question is whether or not there is a better way to do this (i.e. using timediff or some other MySQL command). The issue is the ‘pause’ timestamp doesn’t exist until I make the INSERT, so I feel like that needs to happen first before I can make any calculation?
Well if your table is like this and your requirement is like this then you are on track..
However better if you check the second difference between last row and last to last row. This will give you idea for how many second user has PAUSED or Played the TRACK.
Put action as you like so you can insert time difference between two.