Assuming the array of the mysql looks like this:
$array1=array('A'=>100, 'B'=>200, 'C'=>39);
$array2=array('A'=>467, 'B'=>29, 'C'=>89);
Use arsort:
arsort($array1);
arsort($array2);
The second parameter is: sort_flags
Which uses these types:
SORT_REGULAR - compare items normally (don't change types)
SORT_NUMERIC - compare items numerically
SORT_STRING - compare items as strings
SORT_LOCALE_STRING - compare items as strings, based on the current
locale. It uses the locale, which can be changed using setlocale()
SORT_NATURAL - compare items as strings using "natural ordering" like
natsort()
SORT_FLAG_CASE - can be combined (bitwise OR) with SORT_STRING or
SORT_NATURAL to sort strings case-insensitively
So you could use arsort($array1,SORT_NUMERIC);
After sorting it, you can loop through it like this:
$x=1;
foreach ($array1 as $key => $val) {
echo $key.' - '.$x;
$x++;
}