SonicUK Posted December 1, 2007 Share Posted December 1, 2007 Ok here's the array: $DKP_table { [1] ['id'] = 1 ['name'] = Treachery ['class'] = Warrior ['dkp'] = 50 [2] ['id'] = 2 ['name'] = Bob ['class'] = Paladin ['dkp'] = 35 [3] ['id'] = 3 ['name'] = Hadria ['class'] = Druid ['dkp'] = 60 } foreach ($DKP_table as $value) { print the table } What i need is for the it to be sorted by ['name'] , ['dkp'] or ['class']. Its not really essential just a nice feature. Can this be done? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted December 2, 2007 Share Posted December 2, 2007 Check out array_multisort http://www.php.net/array_multisort Also, if you are querying this data from a database, why not use SQL to sort? Quote Link to comment Share on other sites More sharing options...
SonicUK Posted December 2, 2007 Author Share Posted December 2, 2007 Thanks. I had looked at that page briefly before but didnt really understand half of it.. when i looked again i found an example which did what i want: $sort_arr = array(); foreach($DKP_table AS $uniqid => $row){ foreach($row AS $key=>$value){ $sort_arr[$key][$uniqid] = $value; } } array_multisort($sort_arr['dkp'], SORT_DESC, $DKP_table); foreach ($DKP_table as $value) { print the table } This is for a Guild website for world of warcraft btw, and this is my first projecting doing something more than me just muckin around. err the reason i didnt sort directly from sql is because the data is coming from 3 tables. 1 holds the list of players, another holds a list of awards, the 3rd is a linking table which has the id's of which players got which awards. Each table goes into an array, and then it calculates how much each player got in total. Anyway, seems to work fine. I'll be making that code abit more flexable ofc to use on other things. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted December 2, 2007 Share Posted December 2, 2007 Use a join to get the data into a single query... SELECT players.*, awards.name FROM players, awards WHERE players.id = awards.player_id ORDER BY name, dkp, class Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.