Jump to content

Problem in mysql_query Insert with On Duplicate key


newphpbees

Recommended Posts

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

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());

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.