Jump to content

[SOLVED] IF statements in MySql UPDATE


Beauford

Recommended Posts

I posted this in the MySQL group, but it might be relevent here as well. If not, I apologize for the post.

 

I am trying to add interest to a dollar value, but I don't want the interest to go higher than a certain number.

 

Example

 

(update table set SET bankmoney = IF (bankmoney * .02 < 1000, bankmoney=bankmoney * .02 else bankmoney = bankmoney + 1000);

 

Of course the above doesn't work, The question is, how do I get it to work.

 

Thanks. I only have one gray hair left and I'd like to keep it.

 

B

Link to comment
Share on other sites

I actually figured it out using a where statement and it works perfectly. I just had to use two statements.

 

 

Then post those two.

 

$db->query("UPDATE users set bankmoney = bankmoney+bankmoney * .02 where (bankmoney > 0 and bankmoney * .02 < 300000) and donatordays = 0");

$db->query("UPDATE users set bankmoney = bankmoney+300000 where (bankmoney > 0 and bankmoney * .02 > 300000) and donatordays = 0");

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.