php - Update mysql date fields in table using case -


i have match table:

| mid | home | away | dateupdated | dateresultsentered | |  1  |  30  |  5   |   30/07/15  |      30/07/15      | |  2  |  14  |  12  |   30/07/15  |      29/07/15      | |  3  |  41  |  21  |   30/07/15  |      28/07/15      | |  4  |  30  |  14  |   30/07/15  |      28/07/15      | |  5  | null | null |   30/07/15  |      null          | |  6  | null | null |   30/07/15  |      null          | 

each row updated when user submits results table in web application. i'm trying write update query such if home column has value, not change dateresultsentered column. of user submitted values null (ie not entered)

this sql repeated every mid in table in php code using foreach loop:

update `match`    set       home = 20 ,       away = 12 ,      dateupdated = now() ,       dateresultsentered = case when home not null                                  , dateresultsentered null                                  now()                                     else                                 null                                  end  mid = 5  

this seems update dateresultsentered column values now() wherever there value in home.

i'm wanting dateresultsentered column save current date when home column changes null integer

can me write query?

what about

update `match` set       home = 20 ,       away = 12 ,      dateupdated = now() ,       dateresultsentered = now() mid = 5 , dateresultsentered null , home not null  

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -