selectQuery($query)->array_data; // Sort alphabetically, and compute min and max $min = 1000000; $max = -1; function sort_by_name($s0, $s1) { global $min, $max; $min = min($min, $s0['tag_usage']); $max = max($max, $s0['tag_usage']); // The tags can't be equal. For they are tags. return ($s0['tag_name'] > $s1['tag_name']) ? +1 : -1; } usort($res, 'sort_by_name'); // Add popularity info $delta = $max - $min; $delta = $delta > 0 ? $delta : 1; function add_popularity($s) { global $min, $delta; $s['popularity'] = round(($s['tag_usage'] - $min) / ($delta / POPULARITY_RANKS)); return $s; } $res = array_map('add_popularity', $res); // Save into a genfile genfile::write(genfile::makeGenfileName('tagcloud'), $res) or die("Unable to save data in a genfile.\n"); echo "OK.\n"; ?>