Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Questions and Supports (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=18)
-   -   Filtered dropdown of all of a user's adopts? (http://www.mysidiaadoptables.com/forum/showthread.php?t=5457)

aquapyrofan 05-30-2017 01:05 PM

Filtered dropdown of all of a user's adopts?
 
I know there's a way to do it, since it's done for the Favpet selection and for breeding, but I need to know how. I also need to know how the dropdown can know the adoptable id, since I'm going to be using it for other things.

Dinocanid 05-30-2017 02:41 PM

To filter which pets show up in the dropdown, you use this for the conditions:
PHP Code:

$stmt $mysidia->db->select("owned_adoptables", array("name""aid"), "owner = '{$mysidia->user->username}' AND column = value"); 

So you would replace 'column' and 'value' with whatever you want. (you can use AND as much as you want too if you wanted to narrow it down further) Here is an example if it being used to only select pets that are level 3 or higher:
PHP Code:

$stmt $mysidia->db->select("owned_adoptables", array("name""aid"), "owner = '{$mysidia->user->username}' AND currentlevel >= 3"); 

And here is an example found in breeding.php, which narrows down the list to pets of a certain gender, level, and last time bred:
PHP Code:

$stmt $mysidia->db->select("owned_adoptables", array("name""aid"), "owner = '{$mysidia->user->username}' AND gender = 'f' AND currentlevel >= {$settings->level} AND lastbred <= '{$lasttime}'"); 

For getting the id of the pet, you have to use 'fetchmap', like this:
PHP Code:

$stmt $mysidia->db->select("owned_adoptables", array("name""aid"), "owner = '{$mysidia->user->username}' AND currentlevel >= 3");
        
$adopts $mysidia->db->fetchMap($stmt);
//code...
$petlist = new DropdownList("petlist");
          
$petlist->add(new Option("None Selected""none"FALSE));            
          
$petlist->fill($adopts);
$yourForm->add($petlist); 

That way the pet id is inserted into the database instead of the name, unlike it would've done if you used 'fetchlist', which would get the name but nothing else.

aquapyrofan 05-30-2017 03:50 PM

Quote:

Originally Posted by Dinocanid (Post 36389)
To filter which pets show up in the dropdown, you use this for the conditions:
PHP Code:

$stmt $mysidia->db->select("owned_adoptables", array("name""aid"), "owner = '{$mysidia->user->username}' AND column = value"); 

So you would replace 'column' and 'value' with whatever you want. (you can use AND as much as you want too if you wanted to narrow it down further) Here is an example if it being used to only select pets that are level 3 or higher:
PHP Code:

$stmt $mysidia->db->select("owned_adoptables", array("name""aid"), "owner = '{$mysidia->user->username}' AND currentlevel >= 3"); 

And here is an example found in breeding.php, which narrows down the list to pets of a certain gender, level, and last time bred:
PHP Code:

$stmt $mysidia->db->select("owned_adoptables", array("name""aid"), "owner = '{$mysidia->user->username}' AND gender = 'f' AND currentlevel >= {$settings->level} AND lastbred <= '{$lasttime}'"); 

For getting the id of the pet, you have to use 'fetchmap', like this:
PHP Code:

$stmt $mysidia->db->select("owned_adoptables", array("name""aid"), "owner = '{$mysidia->user->username}' AND currentlevel >= 3");
        
$adopts $mysidia->db->fetchMap($stmt);
//code...
$petlist = new DropdownList("petlist");
          
$petlist->add(new Option("None Selected""none"FALSE));            
          
$petlist->fill($adopts);
$yourForm->add($petlist); 

That way the pet id is inserted into the database instead of the name, unlike it would've done if you used 'fetchlist', which would get the name but nothing else.

Is there a way to add the ID without the database call (say, another form element) so it can then be used elsewhere? I'm planning to try to do something with JavaScript and will need a way for it to know which pet the user is selecting.

Dinocanid 05-30-2017 05:07 PM

You can get the result of the form when submitted and use the id from there, no need to add anything to the database and call it back if it isn't necessary for what you're trying to accomplish:
PHP Code:

$somevariable $mysidia->input->post("petlist"); 

(Following the example code above)
Now you can use '$somevariable' to get the id of the chosen pet and use it elsewhere in the script; like so:
PHP Code:

if($mysidia->input->post("submit")){
            
$petid $mysidia->input->post("petlist");
/*javascript goes here*/


This is in a case where it gets the id if the user clicks a submit button. If you wanted to do something that updates without reloading/changing pages then I doubt you would use this exact code, but you can still get the id the same way.


All times are GMT -5. The time now is 02:08 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.