Thread: Re
View Single Post
  #2  
Old 06-05-2014, 12:49 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 22,320
IntoRain is on a distinguished road
Default

Okay a few things I think you are confusing.

1)
This:

public function setAdoptObedience(){
$query = "INSERT INTO adopts_owned_adoptables
(obedience)
WHERE aid = $this->aid;
VALUES
($obedience)";
$mysidia->db->exec($query);
}

Use $mysidia->db->insert("table_name_without_prefix",array("name_of _attribute" => $value_of_attribute,"another" => $more_values)) to insert new objects into tables

Use $mysidia->db->update("table_name_without_prefix",array("name_of _attribute" => $value_of_attribute,"another" => $more_values),"attribute = $value and anotherattribute = $value") to update values in the table. Your adoptables already exist, you just want to update their information. In OwnedAdoptables you don't create a new OwnedAdptable, you just get or set new information, by selecting something from the database or updating it.

2)
To get a random value use rand(min_value,max_value).

3)
Your setObedience function returns no value at all, so in adopt.php doing variable = setObedience() doesn't store anything.

4)
The new adopt is only added to the database after the line mysidia->db->insert("owned_adoptables",...). Before that line, he's an Adoptable, so the adopt->setObedience() function doesn't exist for an Adoptable, since you created it for an OwnedAdoptable.

5) In fact, in adopt.php the line mysidia->db->insert("owned_adoptables",...) creates the adopt, you can't use a query before the adopt actually existing on the table. You can just get a random variable before the insert and in the insert add the obedience value. Like:

PHP Code:
...
$adoptobedience rand(min_value,max_value);
$gender $adopt->getGender(); 
$mysidia->db->insert("owned_adoptables", array("aid" => NULL"type" => $adopt->getType(), "name" => $name"owner" => $mysidia->user->username"currentlevel" => 0"totalclicks" => 0"code" => $code"imageurl" => NULL"usealternates" => $alts"tradestatus" => 'fortrade'"isfrozen" => 'no'"gender" => $gender"lastbred" => 0"obedience" => $adoptobedience)); 
__________________


asp.net stole my soul.
Reply With Quote