Site
Home / Forum / Developers / Criterias

Criterias


Posted: 02 May 2021 10:27


Hi,
By default the datas are sorted by a way, if i want to change this sort criteria is it possible.
For example, these datas https://www.thesportsdb.com/api/v1/json/1/all_leagues.php are sorted by idLeague.
If i want to sort them by strLeague (to get the leagues in an alphabetical order), can i do it ?
If yes, how to do ? is it a parameter to add in the url ?

Thanks

Posted: 03 May 2021 03:46
willorkney

Posts: 13
Joined: 2021

I use jQuery/Ajax to fetch data from the API so I only have a jQuery/Ajax example, but I'm sure this can be done in PHP and other languages too. I've quickly put together a working example in jQuery showing how to do this, hope it helps

Edit: My code was removed when I tried to post it here, probably for forum security. I've posted it as a .txt file at https://chzfans.com/sort_by.html.txt - just copy this code into Notepad on your end and save it as a .html file to run it on your end.

I've put up a live copy of the above script for you to check at https://chzfans.com/sort_by.html

Posted: 03 May 2021 05:03


Hi,

Thanks I will see it.
I don't know Jquery / Ajax, just try to learn by myself.
I just know how to fetch datas in PHP
Your script works also for numeric values ?

Regards

Posted: 03 May 2021 17:53

zag


Posts: 3,503
Joined: 2020

Should be pretty easy in PHP using json decode and then:

https://www.w3schools.com/php/php_arrays_sort.asp

Posted: 03 May 2021 18:15


That's what I use, PHP with json_decode (just need to learn to do the sort)
Seems difficult.
Visibly, a sort() is made on an array, not on a json_decode.



Who is Online?

In total there are 68 users online :: 3 registered, 0 hidden and 65 guests (based on users active over the past 5 minutes) Most users ever online was 424 on Fri Nov 10, 2017 9:02 pm

About Us

Discussion forum for TheSportsDB.com site and related topics

Rules

- Be Polite
- Respect other users
- Always post log files with issues
- Try to be helpful
- No Piracy discussion

Showing 0 to 5 (Total: 5)