Hello,
At first, my apologies for not yet knowing the exact php terms which may make the issue slightly more complicated than it actually is.
I am currently working on a game, to which the user data is linked to my database.
Now I want to use parts of the users' data and put that in a highscore list.
The way it works so far:
I load the data of each players in an array, so in other words, each player has its own array, containing the required information. The code looks the following:
for($i=2; $i<$num_players; $i++) //start at 2 in order to skip the admin account (which has an ID of 1 in the database)
{
$playerID[$i] = mysql_query("SELECT * FROM `tbl_gamestats` WHERE ID='$i'");
$player[$i] = mysql_fetch_assoc($playerID[$i]);
$place[$i] = Array("name"=>$player[$i]["username"],"level"=>$player[$i]["level"],"experience"=>$player[$i]["ownexp"],"money"=>$player[$i]["money"]);
}
Ok, so probably as anyone will be able to figure out, this will return the arrays for each player (containing their name, level, experience and money, where 'i' is equivalent to their ID in the database.
Now here comes the "tricky" part:
I want to sort these arrays on level, from high to low (descending), in a way it still also remembers which username belongs to its corresponding level.
//Sorting code
//What should I put here in order to sort $place on "level"?
And then eventually here print the sorted output in the highscores list.
for($i=0; $i<$num_players-2; $i++) //Depending on how the <sort> function works, I may have to start $i at either 0, 1 or 2
{
print_r($place[$i]);
echo "<br/>";
}
Hopefully one of you can help me solve this problem 🙂