Hello Everyone,

i am wanting to build a leaderboard for my site for the members gamerscore on Xbox LIVE. I know how to fech from a MySQL database, etc but this is the hard bit.

So the users table in MySQL contains their gamertag and i want to pull that out for each user and then get there gamerscore from a xml external below i will show you how to do it for one user which i use on their profile pages but i want a top 100 and the only prblem is that i have over 5000 members.

So here it is:

$gamertag = $fetch['gamertag'];
$xmlLocation = "http://xboxapi.duncanmackenzie.net/gamertag.ashx?GamerTag=".$gamertag;
$Gamerinfo = simplexml_load_file($xmlLocation);
	  
echo "Gamerscore: ".$Gamerinfo->GamerScore;

Now i think this would maybe go into a loop of some sort? But thanks and please help if you can.

Daniel

Using a loop on 5000 members would take too much time simply because of the delay between the request and response of your xml request to the API.

I think that the best thing you can do, is requesting everyone's gamerscore once, putting it in the table, and then using that data to create your leaderboards. Although these scores are potentially "old", you can sort and display the data almost instantly.

In order to keep the scores updates, make sure you schedule a script to automatically refresh everyone's score once a day/week/...

Also, you could use this old data to fetch the top 150 (or something like that, at least more than the number you want to show) and refresh the score of the users in this list more often.

Thank you for your reply this was very helpful to me.

Regards,

Daniel

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.