[1.3.6]Fix Merging Dropdown Items

Forum
Last Post
Threads / Messages

KittHaven

Member
Member
Joined
May 21, 2013
Messages
483
Points
28
Age
25
Location
Devon, UK
Mysidian Dollar
8,389
Hi! An ongoing issue some of you might have encountered is with items that have a duplicate name merging in lists. For example you might notice if you have multiple adopts with the same name you can only see one entry in the breed adopt dropdowns.

2024-07-27 21_36_49-Bean Pets _ Breed - Opera.png
(I actually have 4 male adopts, all called Unnamed!)

In this small tutorial we're going to fix it!

Find and open resource/core/database.php.

Find:
PHP:
public function fetchMap(PDOStatement $stmt){
        $map = new LinkedHashMap;
        while($fields = $stmt->fetch(PDO::FETCH_NUM)){
            if(count($fields) == 1) $fields[1] = $fields[0];
            $map->put(new MysString($fields[0]), new MysString($fields[1]));
        }
        return $map;
    }

Underneath it, put this:
PHP:
public function fetchMapID(PDOStatement $stmt){
        $map = new LinkedHashMap;
        while($fields = $stmt->fetch(PDO::FETCH_NUM)){
            if(count($fields) == 1) $fields[1] = $fields[0];
            $map->put(new MysString("{$fields[0]} [ID: {$fields[1]}]"), new MysString($fields[1]));
        }
        return $map;
    }

Now you can open service/helper/formhelper.php and in any function where you see fetchMap and you want to display both the name and ID of the item, replace fetchMap with fetchMapID!

2024-07-27 21_37_03-Bean Pets _ Breed - Opera.png

I added a new function as not all lists need or can display an ID, and you might not want or need to replace them all.

Some functions I recommend replacing are:

buildUsernameList,
buildAdoptTypeList,
buildItemShopList,
buildAdoptShopList,
buildItemNameList


In other files, I recommend:

controller/main/accountcontroller.php public function profile
controller/main/breedingcontroller.php public function index (do it for both male and female adopts)
service/applicationservice/tradeservice.php (do it for all instances, there should be 6)

Finally, in controller/main/inventorycontroller.php (it's a special case) find:
PHP:
$stmt = $mysidia->db->select("owned_adoptables", ["aid", "name"], "owner = '{$mysidia->user->getID()}'");
        $map = $mysidia->db->fetchMap($stmt);

Replace with:
PHP:
$stmt = $mysidia->db->select("owned_adoptables", ["name", "aid"], "owner = '{$mysidia->user->getID()}'");
        $map = $mysidia->db->fetchMapID($stmt);


If you need any help, let me know and I can try to troubleshoot!
 
THANK YOU, I plan to use this ASAP, this always has perplexed me why it does this and I think it'll be a huge help since we lean on breeding for some special outcomes.

Edit: I installed it, and not seeing any issues yet!
 
Last edited:
Just found a potential issue with the
controller/main/inventorycontroller.php
Change

it's showing only the ID not the name
1725145068843.png

and on use, it's kicking an error the user doesn't own the adoption (even though they do), but it IS showing the name on the error

1725145108133.png
 
Just found a potential issue with the
controller/main/inventorycontroller.php
Change

it's showing only the ID not the name
View attachment 853

and on use, it's kicking an error the user doesn't own the adoption (even though they do), but it IS showing the name on the error

View attachment 854
Did you remember to change the:

Code:
$stmt = $mysidia->db->select("owned_adoptables", ["aid", "name"], "owner = '{$mysidia->user->getID()}'");
        $map = $mysidia->db->fetchMap($stmt);

to:

Code:
$stmt = $mysidia->db->select("owned_adoptables", ["name", "aid"], "owner = '{$mysidia->user->getID()}'");
        $map = $mysidia->db->fetchMapID($stmt);

I just ask because by default Mys will display the ID and use the name as the value, so you need to swap the order of "aid", "name" so it displays the name and uses the ID as the value instead. It's why it's a special case as it seems like this is the only location it does this for some reason :unsure: Let me know if that fixes it!
 
I did i currently redid in full like this, i even redid the file to make sure and it's still happening


Code:
 $stmt = $mysidia->db->select("owned_adoptables", ["name", "aid"], "owner = '{$mysidia->user->getID()}'");
        $map = $mysidia->db->fetchMapID($stmt);
        $this->setField("item", $item);
        $this->setField("petMap", $map);
 
Last edited:
Did you remember to change the:

Code:
$stmt = $mysidia->db->select("owned_adoptables", ["aid", "name"], "owner = '{$mysidia->user->getID()}'");
        $map = $mysidia->db->fetchMap($stmt);

to:

Code:
$stmt = $mysidia->db->select("owned_adoptables", ["name", "aid"], "owner = '{$mysidia->user->getID()}'");
        $map = $mysidia->db->fetchMapID($stmt);

I just ask because by default Mys will display the ID and use the name as the value, so you need to swap the order of "aid", "name" so it displays the name and uses the ID as the value instead. It's why it's a special case as it seems like this is the only location it does this for some reason :unsure: Let me know if that fixes it!
Not sure if this helps troubleshoot but if I revert it back to the original code, the names separate out it just doesn't show ID
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,290
Messages
33,174
Members
1,605
Latest member
thirddivision
BETA

Latest Threads

Latest Posts

Top