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)
-   -   Sort "myadopts" page (http://www.mysidiaadoptables.com/forum/showthread.php?t=2199)

SilverDragonTears 06-13-2011 08:07 PM

Sort "myadopts" page
 
Is there a way to let users sort their adoptables into the order they want?

SilverDragonTears 06-15-2011 11:39 AM

anyone? =( My members are requesting this and I've no idea how to implement it.

fadillzzz 06-15-2011 11:50 AM

Could you be more specific?
In what order do they actually want? By the total clicks? levels? names? ascending or descending?
Or something more customizable like, they have full control which one is the first, second, third, and so on regardless of the adoptables' stats?

SilverDragonTears 06-15-2011 11:57 AM

More customizable where they can sort which is first,second etc, regardless of the stats =p The other I could do but I don't have any idea how to make it so they can sort them and save the order.

fadillzzz 06-15-2011 12:16 PM

You'll need to create a new table for that
I'm thinking the table would be something like this
-----------------------------------
|adoptable_id|sorting_number|
-----------------------------------
|_________1|____________2|
|_________2|____________3|
|_________7|____________1|
|_________4|____________1|
...

And then when you're fetching the adoptables from the owned_adoptables table, join it with the other table above and order the rows by the sorting_number field.

SilverDragonTears 06-15-2011 12:33 PM

Ok, how would I go about allowing them to actually sort them... and how to join the tables? I've no idea where to start and can follow code but I'm not advanced by any means =p

fadillzzz 06-15-2011 12:51 PM

To allow users to sort their adoptables, you can create a page where it lists all their own adoptables and put a textbox next to each adoptable for them to input the sorting number.

The JOIN query would probably look like this
SELECT * FROM adopts_owned_adoptables JOIN adopts_sorting_adoptables ON adoptable_id = aid ORDER BY sorting_number ASC;

I think that should do it (for the query part)

Ruinily 06-15-2011 03:51 PM

This is great, I've been dying for something like this for ages! I'll be trying it out soon too after straightening out some other little things and see if it works for me. :)

SilverDragonTears 06-15-2011 06:28 PM

Got it working thanks to an awesome friend. Now my next issue.

Is it possible to give my users a link for other people to see the adoptables they own?

EDIT: nm =p friend is doing that as well.. I luuuv this guy!

Ruinily 06-15-2011 11:36 PM

o.o Where did you get this friend and can I get one? :D

SilverDragonTears 06-17-2011 02:33 PM

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

parayna 06-11-2017 05:50 PM

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...

Dinocanid 06-11-2017 06:06 PM

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)

parayna 06-11-2017 06:28 PM

Thanks! I'll try it out tomorrow because I'm probably too tired to make sense of anything XD

parayna 06-12-2017 01:59 PM

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));
    } 


Dinocanid 06-12-2017 03:09 PM

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.

parayna 06-12-2017 03:34 PM

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

Dinocanid 06-12-2017 03:52 PM

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

parayna 06-12-2017 04:17 PM

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 :ooo:

Dinocanid 06-12-2017 04:30 PM

Still won't work. I'll just stick with what I had xD

parayna 06-12-2017 04:41 PM

OK XD Maybe you have something in your header that is preventing it XD Do you have a redirect already in your header?

Dinocanid 06-12-2017 05:09 PM

I don't have anything in my header as far as I know. Where did you put that line of code, before $mysidia? (directly underneath public function index). I tried putting it both there and in the same spot as the existing redirect; commenting out the current one of course.

EDIT: Putting it above $mysidia doesn't give a white page error, with the warning still appears in the corner and I have to press the button twice for it to work.

parayna 06-12-2017 05:35 PM

Well this is where I have it (using your piece of code in myadoptsview)

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}'");
header("Location: $root/myadopts");
 
exit;  
}
         
        
$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!!! 

It works every time for me o.O A seamless redirect with no stuttering or anything...

EDIT: There might be an error appearing for me but in my php.ini file of WAMP I have errors turned off for things like that. The orange ones appear but the ones that sometimes pop up in the top don't appear anymore. Kyttias did a tutorial for it. I think it was her anyway...

And I also have them turned off on my live site (I develop on WAMP and then test it live, just to make sure it works every so often)

parayna 06-12-2017 05:39 PM

Okay, I think it is my browser! I went on Foodbabs and tried it out, and it works perfectly on your site as well as mine. I use Firefox


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

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