digitex Posted May 16, 2018 Share Posted May 16, 2018 I have a list of users that I want to output in a paginated directory in alphabetical order by last_name. When I first wrote it, my selector looked like this: $members = $pages->find("template=user, roles=member, limit=100"); it sorted correctly as follows: AGLA, H AL, J AL, L BAILEY, M So then I added a sort to ensure it lists by last_name: $members = $pages->find("template=user, roles=member, limit=100, sort=last_name"); The resulting order looks like this: HALLS, T WEBSTER, T AGLA, H AL, J AL, L BAILEY, M The obvious question is why is Halls and Webster coming before Agla? Can anyone explain it for me? I want to add a filter to allow sorting A-Z and Z-A so I need to include a sort in the selector but I need to get it to sort correctly first. Link to comment Share on other sites More sharing options...
Zeka Posted May 16, 2018 Share Posted May 16, 2018 @digitex Are you sure that you don't have space character before H and W letters? 1 Link to comment Share on other sites More sharing options...
zoeck Posted May 17, 2018 Share Posted May 17, 2018 Processwire Sort using PHP "SORT_REGULAR", not "SORT_NATURAL" If you have a string with a upper-case first character, and another one with lowercase first char, then theres a sorting Problem... ? Are your Items all upper-case or mixed? Example: - aSDF - bSDF - Bsdf is sorted like this: - Bsdf - aSDF - bSDF 2 Link to comment Share on other sites More sharing options...
digitex Posted May 17, 2018 Author Share Posted May 17, 2018 14 hours ago, Zeka said: @digitex Are you sure that you don't have space character before H and W letters? That's the first thing I checked. I even cleared the field and re-entered the names manually. That's not it. Link to comment Share on other sites More sharing options...
digitex Posted May 17, 2018 Author Share Posted May 17, 2018 2 hours ago, zoeck said: Processwire Sort using PHP "SORT_REGULAR", not "SORT_NATURAL" If you have a string with a upper-case first character, and another one with lowercase first char, then theres a sorting Problem... ? Are your Items all upper-case or mixed? No the last names are all uppercase. Members were imported from CSV and they were like that on import. It's good to know though. I switched the selector to title instead of last_name and it sorted properly. The only difference I can see between the 2 fields is title is lowercase so I wrote a function to convert all the last_name values to title case and it seems to be working now. I still think it's odd behaviour that uppercase should have sorting issues. Thanks to Zoeck for the insight. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now