简体   繁体   中英

How to add two time stamps to same row in MySQL table at different times

I am working on an internet based time clock and am new to programming. The way I would like this system to work is the user would hit a "clock in" button that would just add a PHP time stamp into the timeIn field in the table then when the user hits the "clock out" button it would add a PHP time stamp to the timeOut field in the same row that timeIn was entered. , along with several other fields like (description of workday, equipment ran, etc.). I have the page built with everything functioning besides the DataBase end of things the problem is that when I click the "clock in" button it adds a new row, then when I hit the "clock out" button it adds another new row with all of the additional information. Is there a simple method to make sure that it all gets added to the same row for that day (assuming the employee does not work past midnight) to keep the DataBase looking clean?

When you are doing the timeIn, You would say something like

INSERT into tablename (employee_id, date, time_in, time_out) VALUES (x, CURDATE(), NOW(), NULL);

When you want to do timeOut,

UPDATE tablename SET time_out = now() WHERE date=CURDATE() AND employee_id='x';

This is not the perfect schema but i hope you got the basic idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM