Sorting Results Alphabetically
Permalink Browser Info Environment
I was wondering if it was possible to sort locations alphabetically rather than by distance?
Type: | Discussion |
---|---|
Status: | New |
Worked perfectly. Thank you.
Does this work with Type/Category as well? I've tried it with the Type attribute, but it still always sorts by distance.
I've tried sorting both ascending and descending and have had no luck.
I changed:
to:
Initially I wanted to sort by distance first and then type/category, so I changed the line to the code below and it didn't work either.
I've tried sorting both ascending and descending and have had no luck.
I changed:
$distanceList->sortBy('distance','ASC');
to:
$distanceList->sortBy('type','DESC');
Initially I wanted to sort by distance first and then type/category, so I changed the line to the code below and it didn't work either.
$distanceList->sortByMultiple('distance ASC','type ASC');
Hello,
I believe that as it stands it sorts by distance no matter what(the distance calculation has actually been baked into the query). If you want to sort by anything else I would just create a new DatabaseItemList
Best Wishes,
Mike
I believe that as it stands it sorts by distance no matter what(the distance calculation has actually been baked into the query). If you want to sort by anything else I would just create a new DatabaseItemList
$dil = new DatabaseItemList; $dil->addToQuery('SELECT * FROM DealerLocatorLocations'); $dil->sortBy('type', 'DESC');
Best Wishes,
Mike
If that's the case, I wonder why this line is needed?
$distanceList->sortBy('distance','ASC');
Ah, yes. My SQL is a bit rusty. I'm surprised that isn't working for you. I'm going to set up a test and see if I can sort that out.
Best Wishes,
Mike
Best Wishes,
Mike
I really only have two types of dealers to list and I tried an if/else statement, but my php ain't the greatest either, so it didn't work.
That's when I scoured the C5 documentation and found the sortByMultiple command.
Thanks for looking into it!
That's when I scoured the C5 documentation and found the sortByMultiple command.
Thanks for looking into it!
Ok, I can probably just give you some SQL to do this. Let me know the exact results you want and I'll write something for it real quick.
Best Wishes,
Mike
Best Wishes,
Mike
I'm using the Type/Category option to indicate a "Gold Dealer". These "Gold Dealers" will be listed first in the sidebar results, then by distance.
I'm currently working on showing a gold icon beside of the Gold Dealers information in the sidebar as well.
Thanks!
I'm currently working on showing a gold icon beside of the Gold Dealers information in the sidebar as well.
Thanks!
Alright, finally broke down and read through the query. The reason you can sort from type is the query isn't selecting it.
Around Line #123 of /dealer_location/models/dealer_locator.php
You'll notice that there isn't type. Let's add that.
Then you should be able to do that sortByMultiple() call just fine. *Hopefully.
Best Wishes,
Mike
Around Line #123 of /dealer_location/models/dealer_locator.php
$q = "SELECT address, address2, postal, name, city, state, lat, lng, phone, country, extra, url,
You'll notice that there isn't type. Let's add that.
$q = "SELECT type, address, address2, postal, name, city, state, lat, lng, phone, country, extra, url,
Then you should be able to do that sortByMultiple() call just fine. *Hopefully.
Best Wishes,
Mike
Still no dice. I've added 'type' to the query and it still only sorts by distance alone. I've tried all of the following ways:
$distanceList->sortByMultiple('distance asc','type desc'); $distanceList->sortByMultiple('distance,asc','type,desc'); $distanceList->sortByMultiple('distance','ASC','type,'DESC');
Hi Tony,
I was way off. I didn't realize this was actually in the block.
/dealer_locator/blocks/dealer_search/tools/search.php
Line #5
to
Sorry about that.
Best Wishes,
Mike
I was way off. I didn't realize this was actually in the block.
/dealer_locator/blocks/dealer_search/tools/search.php
Line #5
$distanceList->sortBy('distance','ASC');
to
$distanceList->sortBy('name', 'DESC');
Sorry about that.
Best Wishes,
Mike
I'm assuming that you'd want the results first filtered by distance from the search address, then sorted alphabetically.
You'd want to override the blocks controller by copying:
/package/dealer_locator/blocks/dealer_search/controller.php
to:
/blocks/dealer_search/controller.php
Then around line 124 you'd comment out the sort by distance and add sort by name.