Show amounts and totals of adoptables

Forum
Last Post
Threads / Messages

Chaos77777

Member
Member
Joined
Jan 18, 2017
Messages
43
Points
6
Mysidian Dollar
0
Hey guys. I almost have it down. I got it showing how many total adopts a player has, but I can't make it show how many different types you own.
PHP:
$array = array($mysidia->db->select("owned_adoptables", array("type")));
$owned = $mysidia->db->select("owned_adoptables", array_unique($array), "owner = '{$mysidia->user->username}'")->rowCount();
$owned1 = $mysidia->db->select("owned_adoptables", array("owner"), "owner = '{$mysidia->user->username}'")->rowCount();

$lang['title'] = "Your Animals. You own {$owned} different species, and {$owned1} total species!";

owned1 shows the total amount a player has, and it works just fine. However, I can't get owned working right, been trying several different ways that I know of (which isn't many lol) with $array, such as $array = array("type") which still shows all owned total, $array = array($adopt->type) which gives me an Uncaught exception 'Exception' with message 'Database error 1054, and I even tried different things with array_unique. No luck. Maybe someone else knows what I'm missing. Thanks guys
 
Last edited:
The array you use inside a db->select() is the array with the names of the columns that have the information you want to retrieve. What array_unique does is to remove duplicates from that array. So you can't use array_unique inside a db->select for what you want to do.

The usual database functionality that does what you want is Select Distinct, however I don't know how to do that with mysidia's database calls without creating a new database function. So I guess the easiest way is like this:

PHP:
$array = $mysidia->db->select("owned_adoptables", array("type"), "owner = '{$mysidia->user->username}'")->fetchAll(PDO::FETCH_UNIQUE);
$owned1 = count($array);
 
->fetchAll(PDO::FETCH_UNIQUE)
That's what I needed, right there. Once again, you're awesome! You get a dedicated thank you on my site when it's ready :D
 
I ran into another snag on this one. Do you happen to know if there's a way I can have it look into two separate arrays? For instance, these don't work, but I think it'll show you what I'm trying to accomplish
$owned1= $mysidia->db->select("owned_adoptables", array("type" AND "subtype"), "owner = '{$mysidia->user->username})->fetchAll(PDO::FETCH_UNIQUE);

$owned1= count($owned);

OR

$owned1= $mysidia->db->select("owned_adoptables", array("type"), "owner = '{$mysidia->user->username} AND subtype= "ALL")->fetchAll(PDO::FETCH_UNIQUE);

$owned1= count($owned);

Since I have it set up to have subtypes of each type lol, It'll count all the types while disregarding the subtypes. I can't just do the array "subtype" because there are subtypes that are the same type and types that are the same subtypes lol :( I didn't think this one through when I started up. The top one disregards my "AND 'subtype'" and only numbers the types. The second one doesn't work cuz there's no subtype "all" lol. Leaving it blank gives the same thing too

Lol I thought I was being smart and doing
$owned1= $mysidia->db->select("owned_adoptables", array("type"), "owner = '{$mysidia->user->username} AND subtype != "")->fetchAll(PDO::FETCH_UNIQUE);

$owned1= count($owned);

But that just gave the same results as the top one
 
Last edited:
Hmm I'm not sure I get it, but would something like this work?

PHP:
$array = $mysidia->db->select("owned_adoptables", array("type", "subtype"), "owner = '{$mysidia->user->username}' GROUP BY type, subtype")->fetchAll();
$owned1 = count($array);
 
:( no, same results. It's only searching by type while disregarding subtype. I'm trying a few other things. If I happen to find something that works, I'll post it. Unless you come up with something first.
 
Say if I have "american" as the type, and "dog" as the subtype. Well, if I have an "american" "cat" also lined up where "american" is also the type of the "cat" subtype, then it still only shows one result. That's just an example, not exactly what I'm doing. I COULD just make their types "American Dog" and "American Cat" and get the proper results, but it would look pretty funny in other areas I set up to have them separated
 
So you have something like this:

27GR2GS.png


The group by I posted should be outputting a count of 4 in this case
 
Yes, but in the case where there would be European Cat at the bottom, it still shows 4. Not 5
 
Say if I have a Bengal type tiger and a Bengal type cat. It shows there's one. Because they're both Bengal. It disregards the subtype "tiger" and "cat"

I derped, lol. I didn't realize you removed the fetch unique pdo. Thanks so much, it does work, I tested it by changing around types and subtypes
 
I derped, lol. I didn't realize you removed the fetch unique pdo. Thanks so much, it does work, I tested it by changing around types and subtypes

Oh, good. I was getting confused because I added an European Cat and it was counting 5 lol

lAJMMff.png


There was also the option to add a CONCAT if it didn't work, so it would be okay xD

Glad it worked out in the end! And yeah, the GROUP BY makes groups by the combination of those two columns, merging the two columns, so there was no need for fetch_unique this time!
 
Welp, I noticed that the shop and pound only takes from the type, not the subtype (Also the owner reward too, from my last post). If I have a Bengal Cat and a Bengal Tiger (Both of which cost different amounts), it costs the same amount to pound it and it only gives the owner the same reward as the Bengal Cat, I'm assuming because it was made first. Any idea where I'd go to change that around?
 
Last edited:
Freakin A! I got it! Before I go on though I want a more expert opinion.
In class_stockadopt
I changed
$row = $mysidia->db->select("adoptables", array(), "type ='{$adopttype}'")->fetchObject();

to

$row = $mysidia->db->select("adoptables", array(), "id ='{$adopttype}'")->fetchObject();

And in class_adoptshop

I changed

foreach($this->adopts as $stockadopt){
$adopt = $this->getadopt($stockadopt->type);

to

foreach($this->adopts as $stockadopt){
$adopt = $this->getadopt($stockadopt->id);



-edit-
That got the right details to show in the shop and pound but
Trying to actually buy it

An error has occurred.

The adoptable specified is invalid...

Boooooooooooo
 
Last edited:
I did a workaround and named the types slightly different atm.
If you'd like, you can check out my site
http://arconline.x10host.com

:( Yeah, I made a dumb@ss typo at the start lol, I'll worry about fixing it later though
 
Last edited:

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,280
Messages
33,129
Members
1,603
Latest member
Monako
BETA

Latest Threads

Latest Posts

Top