Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 01-19-2017, 04:25 PM
Chaos77777 Chaos77777 is offline
Member
 
Join Date: Jan 2017
Posts: 43
Gender: Male
Credits: 3,692
Chaos77777 is on a distinguished road
Default Show amounts and totals of adoptables

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 Code:
$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 by Chaos77777; 01-19-2017 at 04:58 PM.
Reply With Quote
  #2  
Old 01-19-2017, 05:14 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,257
IntoRain is on a distinguished road
Default

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 Code:
$array $mysidia->db->select("owned_adoptables", array("type"), "owner = '{$mysidia->user->username}'")->fetchAll(PDO::FETCH_UNIQUE);
$owned1 count($array); 
__________________


asp.net stole my soul.
Reply With Quote
  #3  
Old 01-19-2017, 05:20 PM
Chaos77777 Chaos77777 is offline
Member
 
Join Date: Jan 2017
Posts: 43
Gender: Male
Credits: 3,692
Chaos77777 is on a distinguished road
Default

->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
Reply With Quote
  #4  
Old 01-19-2017, 05:27 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,257
IntoRain is on a distinguished road
Default

No problem, glad to help :D
__________________


asp.net stole my soul.
Reply With Quote
  #5  
Old 01-20-2017, 05:17 PM
Chaos77777 Chaos77777 is offline
Member
 
Join Date: Jan 2017
Posts: 43
Gender: Male
Credits: 3,692
Chaos77777 is on a distinguished road
Default

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 by Chaos77777; 01-20-2017 at 05:41 PM.
Reply With Quote
  #6  
Old 01-21-2017, 10:27 AM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,257
IntoRain is on a distinguished road
Default

Hmm I'm not sure I get it, but would something like this work?

PHP Code:
$array $mysidia->db->select("owned_adoptables", array("type""subtype"), "owner = '{$mysidia->user->username}' GROUP BY type, subtype")->fetchAll();
$owned1 count($array); 
__________________


asp.net stole my soul.
Reply With Quote
  #7  
Old 01-21-2017, 11:04 AM
Chaos77777 Chaos77777 is offline
Member
 
Join Date: Jan 2017
Posts: 43
Gender: Male
Credits: 3,692
Chaos77777 is on a distinguished road
Default

:( 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.
Reply With Quote
  #8  
Old 01-21-2017, 11:13 AM
Chaos77777 Chaos77777 is offline
Member
 
Join Date: Jan 2017
Posts: 43
Gender: Male
Credits: 3,692
Chaos77777 is on a distinguished road
Default

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
Reply With Quote
  #9  
Old 01-21-2017, 12:06 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,257
IntoRain is on a distinguished road
Default

So you have something like this:



The group by I posted should be outputting a count of 4 in this case
__________________


asp.net stole my soul.
Reply With Quote
  #10  
Old 01-21-2017, 01:22 PM
Chaos77777 Chaos77777 is offline
Member
 
Join Date: Jan 2017
Posts: 43
Gender: Male
Credits: 3,692
Chaos77777 is on a distinguished road
Default

Yes, but in the case where there would be European Cat at the bottom, it still shows 4. Not 5
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 12:09 PM.

Currently Active Users: 462 (0 members and 462 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636