I am creating an array and then sorting the array on the value. But i want the $row['player_id'] to be the key but after i merge it they have reset the keys and go from 0, 1, 2 and so on etc..... Any ideas anyone???
PHP Code:
// Put Goal Scorers Into An Array $array = array(); $sql2 = mysql_query("SELECT DISTINCT player_id FROM `manager__goals` WHERE `league` = '" . $sql['id'] . "' && `season` = '" . $settings['season'] . "' ORDER BY `goal_id` DESC"); while($row = mysql_fetch_array($sql2)) { $goals = mysql_num_rows(mysql_query("SELECT * FROM `manager__goals` WHERE `league` = '" . $sql['id'] . "' && `season` = '" . $settings['season'] . "' && `player_id` = '" . $row['player_id'] . "'")); echo "" . $row['player_id'] . " - "; $player = array($row['player_id'] => $goals); $array = array_merge($array, $player); } // Sort By Goals Scored arsort($array); // Display Values $i = 0; foreach($array as $key => $value) { $i++; echo "Key: $key; Value: $value<br />\n"; }
|