herghost Posted September 23, 2009 Share Posted September 23, 2009 Hi all, never dealt with maths before so back to school for I have me! I have a table with an int number, how do I go about subtracting one from this and updating the database? Also is there any good guides on this stuff? Many Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/175218-solved-really-basic-maths-question/ Share on other sites More sharing options...
Mark Baker Posted September 23, 2009 Share Posted September 23, 2009 UPDATE table SET field=field-1 WHERE condition Quote Link to comment https://forums.phpfreaks.com/topic/175218-solved-really-basic-maths-question/#findComment-923515 Share on other sites More sharing options...
Maq Posted September 23, 2009 Share Posted September 23, 2009 This can all be done in MySQL. i.e. UPDATE [table] SET [field] = [field] - 1; If you don't have a PHP Math question I'm going to move this to the MySQL Help section. Quote Link to comment https://forums.phpfreaks.com/topic/175218-solved-really-basic-maths-question/#findComment-923516 Share on other sites More sharing options...
herghost Posted September 23, 2009 Author Share Posted September 23, 2009 hi, I am not sure how to write this query: $query = 'UPDATE users_credits SET credits = credits - 1 WHERE username = $username'; This does not change it! Quote Link to comment https://forums.phpfreaks.com/topic/175218-solved-really-basic-maths-question/#findComment-923530 Share on other sites More sharing options...
Maq Posted September 23, 2009 Share Posted September 23, 2009 Variables don't interpolate in single quoted strings. You should use double quotes for your string and single quotes for your string values. $query = "UPDATE users_credits SET credits = credits - 1 WHERE username = '$username'"; A good technique to learn is echoing your query string ($query) to see what you're actually passing. Quote Link to comment https://forums.phpfreaks.com/topic/175218-solved-really-basic-maths-question/#findComment-923534 Share on other sites More sharing options...
herghost Posted September 23, 2009 Author Share Posted September 23, 2009 Thanks Maq Why is it that everytime you think you know a bit, you can never do what you think you can do Quote Link to comment https://forums.phpfreaks.com/topic/175218-solved-really-basic-maths-question/#findComment-923538 Share on other sites More sharing options...
Maq Posted September 23, 2009 Share Posted September 23, 2009 Thanks Maq Why is it that everytime you think you know a bit, you can never do what you think you can do Welcome, heh, don't worry it happens to all of us. Quote Link to comment https://forums.phpfreaks.com/topic/175218-solved-really-basic-maths-question/#findComment-923579 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.