PDA

View Full Version : Problem in mysql_query Insert with On Duplicate key



newphpbees
19 Dec 2011, 02:57 AM
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