[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 880
  • Last Modified:

MySQL Subtraction Problem From PHP (Unsigned Int)

I am trying to subtract the value in the field directly in MySQL. I can add correctly as I have seen the correct updates. However I want to be able to store the negative of the value and not just keep itself at 0.

My query from PHP is as follow:

mysql_query("UPDATE registry SET npurchased = npurchased + '".$qty."', nremain = nremain - '".$qty."' WHERE regid = '".$regid."'" );

The MySQL field nremain is set as an unsigned int.

Please let me know where my problem lies.
0
namsu55
Asked:
namsu55
1 Solution
 
namsu55Author Commented:
Maybe I am a bit crazy today. UNSIGNED. Let me get rid of that.
0
 
kumaranmcaCommented:
Hi

Try the following query... its helpful for you

UPDATE tblrecords SET `leagueID` = leagueID+2, `seriesID`= IF((seriesID-1)<0, 0, seriesID-1) WHERE recordID= 1

mysql_query("UPDATE registry SET npurchased = npurchased + '".$qty."', nremain =IF(( nremain- - '".$qty."')<0, 0,  nremain- - '".$qty."')  WHERE regid = '".$regid."'" );
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now