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
  #11  
Old 06-17-2011, 02:33 PM
SilverDragonTears's Avatar
SilverDragonTears SilverDragonTears is offline
I am your Nemesis.
 
Join Date: Jun 2011
Posts: 1,113
Gender: Female
Credits: 82,330
SilverDragonTears is on a distinguished road
Default

I'm selfish and don't like to share ;)
__________________

Check out SilvaTales
Reply With Quote
  #12  
Old 06-11-2017, 05:50 PM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 16,487
parayna is on a distinguished road
Default

I know this is an old post (like a REALLY old one...) but how would I let users sort their pets? Through a preset list. I've been attempting to work it out but I don't have a good enough grasp of PHP... I can get the dropdown list with the button to show up but I don't know how to make it actually send the info to sort the pets that way..

I'd like them to be able to sort their pets by clicks, level, gender, name, class, and birthday (date adopted, which I have stored in the database as birthday in the format 'June 11th, 2017').

Any help would be much, MUCH, appreciated.. XD Once I see the code I'll know how to add more to it, probably, it's just having no idea where to start...
__________________
It's been a long time. I had so much fun making a site back in 2016 that recently, when I started thinking about it again, I decided to come back and work on something small. It'll probably just be a personal project but who knows? We'll see, anyway.

Reply With Quote
  #13  
Old 06-11-2017, 06:06 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 65,194
Dinocanid is on a distinguished road
Default

I've haven't tried it, but I'm assuming this can be done by storing the user's choice somewhere and changing the sort order based on that. So in myadopts.php, there's this line:
PHP Code:
$stmt $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' ORDER BY totalclicks LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}"); 
Maybe make a column in phpMyAdmin called sort and put the stmt line in an if statement; sort of like this:
PHP Code:
$sort $mysidia->db->select("users", array("sort"), "username = '{$mysidia->user->username}'");

if(
$sort 'clicks'){
    
$stmt $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' ORDER BY totalclicks LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}");
}
elseif(
$sort 'level'){
    
$stmt $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' ORDER BY level LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}");
}
//etc... 
(This is just psuedo-code, so I doubt it would work as-is)
__________________
Reply With Quote
  #14  
Old 06-11-2017, 06:28 PM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 16,487
parayna is on a distinguished road
Default

Thanks! I'll try it out tomorrow because I'm probably too tired to make sense of anything XD
__________________
It's been a long time. I had so much fun making a site back in 2016 that recently, when I started thinking about it again, I decided to come back and work on something small. It'll probably just be a personal project but who knows? We'll see, anyway.

Reply With Quote
  #15  
Old 06-12-2017, 01:59 PM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 16,487
parayna is on a distinguished road
Default

Hmm it doesn't like the elseif parts o.O It basically ignores them and uses the last 'if' statement regardless of what $sort is set as. I also tried making them all 'if' statements just in case but then it just uses the last one as the default, regardless of what is input in the database... I also tried using them in the view file (just as a test XD) and it obviously didn't work lol XD

PHP Code:
    public function index(){
        
$mysidia Registry::get("mysidia");
        
$total $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}'")->rowCount();
        
$pagination = new Pagination($total9"myadopts");
        
$pagination->setPage($mysidia->input->get("page"));    
                
$sort $mysidia->db->select("users", array("sort"), "username = '{$mysidia->user->username}'");
        if(
$sort 'clicks'){
        
$stmt $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' ORDER BY totalclicks LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}");
        }
        
        elseif(
$sort 'gender'){
        
$stmt $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' ORDER BY gender LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}");
        }
        elseif(
$sort 'level'){
        
$stmt $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' ORDER BY currentlevel LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}");
        }
        elseif(
$sort 'name'){
        
$stmt $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' ORDER BY name LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}");
        }

        
$this->setField("pagination"$pagination);
        
$this->setField("stmt", new DatabaseStatement($stmt));
    } 
__________________
It's been a long time. I had so much fun making a site back in 2016 that recently, when I started thinking about it again, I decided to come back and work on something small. It'll probably just be a personal project but who knows? We'll see, anyway.

Reply With Quote
  #16  
Old 06-12-2017, 03:09 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 65,194
Dinocanid is on a distinguished road
Default

I decided to play around with it and I got it working! The refresh is a bit strange, but it works well enough. Otherwise users would have to click on the page link again to see the changes.
For the column in phpMyAdmin, you're going to have to set the default 'as defined' to one of the choices or else you'll get an error.

PHP Code:
    public function index(){
        
$mysidia Registry::get("mysidia");
        
$total $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}'")->rowCount();
        
$pagination = new Pagination($total10"myadopts");
        
$pagination->setPage($mysidia->input->get("page"));    
        
        
//Attempting to sort!
        
$sort $mysidia->db->select("users_options", array("petsort"), "username = '{$mysidia->user->username}'")->fetchColumn();
            switch (
$sort){
    case 
'clicks'
        
$stmt $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' ORDER BY totalclicks LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}");
        break;
    case 
'gender'
        
$stmt $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' ORDER BY gender LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}"); 
        break;
    case 
'level'
        
$stmt $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' ORDER BY currentlevel LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}");
        break;
    case 
'name'
        
$stmt $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' ORDER BY name LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}");
        break;
}
        
        
//Sorting ends here!
        
$this->setField("pagination"$pagination);
        
$this->setField("stmt", new DatabaseStatement($stmt));
    } 
(myadopts.php)
PHP Code:
//This is for sorting!
         
if($mysidia->input->post("sortpets")){
$choice $mysidia->input->post("sortlist");
$mysidia->db->update("users_options", array("petsort" => $choice), "username = '{$mysidia->user->username}'");
$document->add(new Comment("<meta http-equiv='refresh' content='0;url=http://YOURSITE.com/myadopts' />")); 
}
         
        
$sortForm = new Form("sortform""""post");
        
$sort_list = new DropdownList("sortlist");
        
$sort_list->add(new Option("Clicks""clicks"));
        
$sort_list->add(new Option("Gender""gender"));
        
$sort_list->add(new Option("Level""level"));
        
$sort_list->add(new Option("Name""name"));
        
$sortForm->add(new Comment("<b>Sort by:</b>"FALSE));
        
$sortForm->add($sort_list);
        
$sortForm->add(new Button("Sort Pets""sortpets""submit"));
        
$document->add($sortForm);
        
        
//Sorting ends here!!! 
(myadoptsview.php)

I might add this to the tutorials (or mods) section since it seems to be in high demand.
__________________
Reply With Quote
  #17  
Old 06-12-2017, 03:34 PM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 16,487
parayna is on a distinguished road
Default

Awesome! Thanks so much! And people would love it as a mod XD

Also, for the redirect, couldn't you use this instead?

PHP Code:
header("Location: $root/myadopts");
 
exit; 
That way the page doesn't stutter nor ask about a refresh, as my browser popped up saying about the page having to resend information and I had to click 'refresh' for it to go through. It might not be that clean but it works so far XD

And how would I get the button on the same line as the drop down box? It's for purely aesthetic reasons but I have the text as 'Sort by clicks', 'Sort by [whatever]', etc and want the button next to it. Thanks for your help :3
__________________
It's been a long time. I had so much fun making a site back in 2016 that recently, when I started thinking about it again, I decided to come back and work on something small. It'll probably just be a personal project but who knows? We'll see, anyway.

Reply With Quote
  #18  
Old 06-12-2017, 03:52 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 65,194
Dinocanid is on a distinguished road
Default

I tried to do it myself, but couldn't figure it out. You can probably do it manually through css with a div element and positioning it next to the dropdown box, but that could lead to issues depending on the user's window size.

EDIT: I can't seem to get the refresh to work that way on my end, I just get an error:
Quote:
Warning: Cannot modify header information - headers already sent by (output started at /home/adopttes/public_html/myadopts.php:7) in /home/adopttes/public_html/view/myadoptsview.php on line 71
__________________

Last edited by Dinocanid; 06-12-2017 at 04:11 PM.
Reply With Quote
  #19  
Old 06-12-2017, 04:17 PM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 16,487
parayna is on a distinguished road
Default

Okay thanks anyway! ^_^ I'm going to give it a shot!

And maybe try

PHP Code:
header("Location: http://adopttest.mysidiahost.com/myadopts");
 
exit; 
Probably a long shot but I'm thinking maybe it doesn't like the root bit. I'm by no means an experienced coder >.>As you can probably tell by my constant queries XD

All it would mean is you'd have to manually change the link if you change domains
__________________
It's been a long time. I had so much fun making a site back in 2016 that recently, when I started thinking about it again, I decided to come back and work on something small. It'll probably just be a personal project but who knows? We'll see, anyway.

Reply With Quote
  #20  
Old 06-12-2017, 04:30 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 65,194
Dinocanid is on a distinguished road
Default

Still won't work. I'll just stick with what I had xD
__________________
Reply With Quote
Reply


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
"Fairy State" theme by Bobbybighoof (Mysidia 1.3.3) bobbybig Templates and Themes 3 07-18-2018 06:54 PM
Removing of prefix "class", "abstract", "interface" Suggestions FounderSim Suggestions and Feature Requests 3 10-05-2014 05:35 PM
Changing... or "masking" existing URLs Vaporman87 Questions and Supports 7 03-03-2014 07:10 PM
[Updated] AJAX Sortable Adoptables on "myadopts.php" Page fadillzzz Mys v1.2.x Mods 57 05-29-2012 02:16 AM
A php question about changing the "level up" section coffeeaddict Questions and Supports 6 02-26-2011 11:08 AM


All times are GMT -5. The time now is 03:35 AM.

Currently Active Users: 9785 (0 members and 9785 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