Jump to content
cobusbo

Update field but do nothing when field value equals

Recommended Posts

$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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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' ?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.