setup lastupdate field in MySQL on update current_timestamp but doesn't work in JS Datatable row.

setup lastupdate field in MySQL on update current_timestamp but doesn't work in JS Datatable row.

wonglikwonglik Posts: 36Questions: 3Answers: 0

How to setup a last update date field in JS datatable when rows update?

Replies

  • wonglikwonglik Posts: 36Questions: 3Answers: 0

    How to setup a last update date field in MySQL table to record last update in JS Datatable? Already setup a field lastupdate default current_timestamp on update current_timestamp but not working in JS datatable.

  • rf1234rf1234 Posts: 3,021Questions: 88Answers: 421

    Already setup a field lastupdate default current_timestamp on update current_timestamp but not working in JS datatable.

    How can a database field (backend) not work at the frontend? What do you mean by this?

    I use this all the time and it works like a charm. You can use a renderer at the frontend or backend to display it like this for example. With the right plugin you can even order the column ascending or descending (in this case it is descending).

  • allanallan Posts: 63,676Questions: 1Answers: 10,497 Site admin

    Perhaps if you could show us the code you are using, that would help us. If you are submitting the last update value for example, then MySQL won't update the value to the current_timestamp. It only does that if you don't submit a value.

    Allan

  • rf1234rf1234 Posts: 3,021Questions: 88Answers: 421
    edited December 2

    If you are submitting the last update value for example, then MySQL won't update the value to the current_timestamp.

    You can achieve correct updating of the timestamp like this for example. update_time is "current time_stamp, on update current time_stamp". I also save the creator_id and the id of the last updater.

    Field::inst( 'vat_question.update_time' )->set( false ),
    Field::inst( 'vat_question.updater_id' ) ->set(Field::SET_BOTH)
                                             ->setValue( $_SESSION['id'] ),
    Field::inst( 'vat_question.creator_id' ) ->set(Field::SET_CREATE)
                                             ->setValue( $_SESSION['id'] ),
    
  • wonglikwonglik Posts: 36Questions: 3Answers: 0

    I did it. Thank you all so much.

Sign In or Register to comment.