cobusbo Posted December 11, 2015 Share Posted December 11, 2015 $sql = "UPDATE `Room_users` SET `kick` = :kick WHERE kick < UNIX_TIMESTAMP()"; So this is my update query, normally I store the time in the kick field in unix format but there is cases where I store the value "Permanently" in that field as well is there a way to change the query to do nothing if the field value is "Permanently" but if the value is unix time then it should update the query? Quote Link to comment https://forums.phpfreaks.com/topic/299705-update-field-but-do-nothing-when-field-value-equals/ Share on other sites More sharing options...
ginerjm Posted December 11, 2015 Share Posted December 11, 2015 If you are storing a timestamp in the "kick" field, it must be hard to store a text value in there. I'm guessing that you don't have that field defined as a time-related field which makes it hard to use that comparison you have in your where clause. Try defining your kick field as a timestamp and then add another field as a flag to be set when you want "permanent" status set on this record. Quote Link to comment https://forums.phpfreaks.com/topic/299705-update-field-but-do-nothing-when-field-value-equals/#findComment-1527834 Share on other sites More sharing options...
Barand Posted December 12, 2015 Share Posted December 12, 2015 I agree with ginerjm, that's a terrible table design. Make it a datetime field with a value of '9999-12-31 23:59:59' for those that are permanent. Then your query works as it is now (except you would use NOW() instead of UNIX_TIMESTAMP() ) As it is now, are you saying you want to update the "kick" fields where kick < UNIX_TIMESTAMP() AND kick <> 'Permanently' ? Quote Link to comment https://forums.phpfreaks.com/topic/299705-update-field-but-do-nothing-when-field-value-equals/#findComment-1527849 Share on other sites More sharing options...
maxxd Posted December 12, 2015 Share Posted December 12, 2015 Or set the value to null for those that are permanent. Then you can simply add a not null check to your query WHERE string. Quote Link to comment https://forums.phpfreaks.com/topic/299705-update-field-but-do-nothing-when-field-value-equals/#findComment-1527862 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.