View Single Post
  #2  
Old 02-07-2017, 07:43 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 87,453
Kyttias is on a distinguished road
Default

You'll have to get the current value(s) first and then subtract. The update function just sets the variable to whatever you tell it to, but cannot math at it.

This would be an example of how to reduce the current user's money:
PHP Code:
$moneyleft $mysidia->user->money $cost;
$mysidia->db->update("users", array("money" => $moneyleft), "username = '{$adopt->owner}'"); 
Going off that, I can do this (but I'm not sure where your code is so this example goes over the top - I'm specifying exactly which adoptable's mood is being modified):
PHP Code:
$adopt = new OwnedAdoptable($aid);
$mood $mysidia->db->select("owned_adoptables", array("mood"), "aid = '{$adopt->getAdoptID()}'")->fetchColumn();
$mysidia->db->update("owned_adoptables", array("mood" => $mood 2), "aid = '{$adopt->getAdoptID()}'"); 
But, again, that might be overboard. The above should work on 'any' page, theoretically. However, $this->adopt->mood might grab the value just fine in levelup.php, or in class_ownedadoptable.php, $this->mood. I'd personally recommend creating a function in class_ownedadoptable.php and calling that from whatever page you need. As mood is a custom variable, you should list it at the top of class_ownedadoptable.php with the other variables if you haven't yet.

PHP Code:
// using "$this->adopt->" in levelup.php:
$mysidia->db->update("owned_adoptables", array("mood" => $this->adopt->mood 2), "aid = '{$this->adopt->getAdoptID()}'");

// or perhaps just "$this->" in class_ownedadoptable.php:
$mysidia->db->update("owned_adoptables", array("mood" => $this->mood 2), "aid = '{$this->aid}'"); 
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 02-07-2017 at 07:50 PM.
Reply With Quote