newphpbees Posted December 19, 2011 Share Posted December 19, 2011 Hi... Before I have no problem in using On Duplicate Key, but now i have because of using time function. Before I only have insert query: $result = mysql_query("INSERT INTO regular_sum_hours(EMP_NO, Hours) SELECT EMP_NO, sec_to_time(SUM(time_to_sec(Rendered))) FROM regular_dtr_total GROUP BY EMP_NO") or die(mysql_error()); And now I think that I need to add a syntax for Update, so i revise my code: $result = mysql_query("INSERT INTO regular_sum_hours(EMP_NO, Hours) SELECT EMP_NO, sec_to_time(SUM(time_to_sec(Rendered))) FROM regular_dtr_total GROUP BY EMP_NO ON DUPLICATE KEY EMP_NO = EMP_NO, Hours = sec_to_time(SUM(time_to_sec(Rendered)))") or die(mysql_error()); and I got a problem in this part: Hours = sec_to_time(SUM(time_to_sec(Rendered)))") Thank you Quote Link to comment https://forums.phpfreaks.com/topic/253465-problem-in-mysql_query-insert-with-on-duplicate-key/ Share on other sites More sharing options...
sasa Posted December 19, 2011 Share Posted December 19, 2011 try $result = mysql_query("INSERT INTO regular_sum_hours(EMP_NO, Hours) SELECT EMP_NO, sec_to_time(SUM(time_to_sec(Rendered))) FROM regular_dtr_total GROUP BY EMP_NO ON DUPLICATE KEY Hours = VALUES(Hours)") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/253465-problem-in-mysql_query-insert-with-on-duplicate-key/#findComment-1299418 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.