Use Owned_Adoptable to call Adoptable?

Forum
Last Post
Threads / Messages

aquapyrofan

Member
Member
Joined
Apr 22, 2017
Messages
48
Points
0
Mysidian Dollar
5,119
For my site, I'm tying a lot of traits to species (prefix_adoptable) rather than to individual pets (prefix_owned_adoptable). Problem is, for things like profiles and items, I need to be able to get those values for the pet's species, using the pet's information. How do I call the other table?
 
To call data from the adoptables table (or any table), you would just use a line of code likes this:

HTML:
$mysidia->db->select("adoptable", array("Column"), "Row = '$somevalue'")->fetchColumn();

With "adoptable" being the table name. It is case-sensitive though, so it must be exactly how it is typed in phpMyAdmin. Just change adoptable to owned_adoptables if you want that table.

If you're trying to define a variable or something, it would look like this:
HTML:
$trait = $mysidia->db->select("adoptable", array("Column"), "Row = '$somevalue'")->fetchColumn();
Then you can just use $trait to call it in the php file whenever you need it, instead of calling the table every time. (replacing trait with whatever you would call it of course)
 
To call data from the adoptables table (or any table), you would just use a line of code likes this:

HTML:
$mysidia->db->select("adoptable", array("Column"), "Row = '$somevalue'")->fetchColumn();

With "adoptable" being the table name. It is case-sensitive though, so it must be exactly how it is typed in phpMyAdmin. Just change adoptable to owned_adoptables if you want that table.

If you're trying to define a variable or something, it would look like this:
HTML:
$trait = $mysidia->db->select("adoptable", array("Column"), "Row = '$somevalue'")->fetchColumn();
Then you can just use $trait to call it in the php file whenever you need it, instead of calling the table every time. (replacing trait with whatever you would call it of course)

Is this how I'd use the owned_adoptables "type" value to call a value in adoptables? I'm confused because it doesn't seem like it.
 
I can't understand you're question too well, so I probably gave you the wrong code just now, sorry ^^;
Are you trying to get the species of a user's pet and use that to fetch the traits?
 
Taking over for aqua here, since I'm the one who does most of the code work for our site. And yes, that's exactly what we were trying to do.
 
Oh! Okay, then you would first get the species of the user's adopt with this:
$aid = $this->getField("aid")->getValue();
$adopt = new OwnedAdoptable($aid);
$type = $adopt->getType();
If you're using the manage function in myadoptsview.php. Then from there it depends on how the traits are stored. If they have their own separate columns in the database then you could do something like:
if($type = "insertspecieshere"){
$trait1 = $mysidia->db->select("adoptables", array("yourtrait"), "type = '{$type}'")->fetchColumn();
}
This is assuming that, in the prefix_adoptables table, each trait is a seperate column and not all bunched into one column. Then, depending on the species, the first trait will be changed accordingly. Then to show the trait to the user you could do this:
$document->add(new Comment("Traits: {$trait1}, {$trait2}, etc..."));
 
Alright, and I'm going to need to use db referrals instead of getWhatever, if I need to use these in an item function, yeah?
 
To get a pet's info from the database, you would need to get the ID of the pet somehow. In the case of items, items get the ID of a pet like this:
$adopt->aid
in functions_items.php. (Which is where you define what a certain item does)
I haven't tried, but I'm assuming $adopt->getType(); or $adopt->getType would still work. This is because items already call the pet that it's about to be used on so you don't have to use the whole database call to get it. From there, the code should still work the same.
 
Unfortunately, the getFoo() functions don't seem to work in that file - I had it error out frequently when I tried, complaining of invalid something. The alternative seems to be manually calling it, but I think I can get it working. I'll swing back and let you know if it does.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,122
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top