romeshomey Posted November 19, 2006 Share Posted November 19, 2006 How can I get this to sort in the opposite direction? NOTE: I tried using rsort but am not familiar with using it and the rest of my script quit working when I tried using the rsort. Ill read up on it and see if I can get it to work, but any help is appreciated.[code=php:0]asort ($opp_fum,SORT_NUMERIC);[/code]For instance I am getting results of as.00001234when I want results of 43210000Thanks Here is the rest of my script if it makes it is helpful.[code=php:0] $query = "select away_team, sum(rushing_yds) as opp_rushyds, sum(rushing_att) as opp_att, sum(rushing_td) as opp_td, sum(rushing_fum)as opp_fum from game_summary, game_rushing where game_summary.game_id=game_rushing.game_id and team=home_team and league_id=1 and season=$max_season and week=$week group by away_team"; $res = mysql_query($query,$db); $num_res = mysql_num_rows($res); for($count=0;$count<$num_res;$count++){ $team = mysql_result($res,$count,"away_team"); $opp_rushyds[$team] = mysql_result($res,$count,"opp_rushyds"); $opp_att[$team] = mysql_result($res,$count,"opp_att"); $opp_td[$team] = mysql_result($res,$count,"opp_td"); $opp_fum[$team] = mysql_result($res,$count,"opp_fum"); } $query = "select home_team, sum(rushing_yds) as opp_rushyds, sum(rushing_att) as opp_att, sum(rushing_td) as opp_td, sum(rushing_fum)as opp_fum from game_summary, game_rushing where game_summary.game_id=game_rushing.game_id and team=away_team and league_id=1 and season=$max_season and week=$week group by home_team"; $res = mysql_query($query,$db); $num_res = mysql_num_rows($res); for($count=0;$count<$num_res;$count++){ $team = mysql_result($res,$count,"home_team"); $opp_rushyds[$team] += mysql_result($res,$count,"opp_rushyds"); $opp_att[$team] += mysql_result($res,$count,"opp_att"); $opp_td[$team] += mysql_result($res,$count,"opp_td"); $opp_fum[$team] += mysql_result($res,$count,"opp_fum"); } asort ($opp_fum,SORT_NUMERIC); reset ($opp_fum); $count=0; while (list ($key, $val) = each ($opp_fum)){ $team = $key; $rank_opp_fum[$key] = $count+1; $count++;[/code] Link to comment https://forums.phpfreaks.com/topic/27739-asort-question/ Share on other sites More sharing options...
printf Posted November 19, 2006 Share Posted November 19, 2006 Do you want to reset the keys, or maintain the key names or numbers?// keep the keys[code]$test = array ( 0, 0, 2, 3, 0, 1, 0, 4 );[/code][code]Array( [7] => 4 [3] => 3 [2] => 2 [5] => 1 [1] => 0 [6] => 0 [4] => 0 [0] => 0)[/code]// rest the keys[code]Array( [0] => 4 [1] => 3 [2] => 2 [3] => 1 [4] => 0 [5] => 0 [6] => 0 [7] => 0)[/code]printf Link to comment https://forums.phpfreaks.com/topic/27739-asort-question/#findComment-126910 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.