How to get the result sorted in array format after count?

Hi,

I’m trying to create a tag cloud for my site. Now I have problem to sort the result in the array format as below:

tags=array(‘weddings’ => 32, ‘birthdays’ => 41, ‘landscapes’ => 62, ‘ham’ => 51, ‘chicken’ => 23, ‘food’ => 91, ‘turkey’ => 47, ‘windows’ => 82, ‘apple’ => 27, ‘apple2’ => 37);

What should I do after selecting the data in the query?

$get_tags= mysql_query(“SELECT keywords, COUNT(id) from mytable where keywords!=‘’ group by keywords”)
or die(mysql_error());

Thanks!


$tags = array();
$get_tags= mysql_query("SELECT keywords, COUNT(id) AS myCount from mytable where keywords!='' group by keywords") or die(mysql_error()); 
while ($tag = mysql_fetch_assoc($get_tags))
{
   // example of $tag: array('keywords' => 'weddings', 'myCount' => 32);
   // so now you would want to get an array to use 'keywords' as key, and 'myCount' as value:
   $tags[$tag['keywords']] = $tag['myCount'];
}


PS. it’s better to use [ code ] and [/ code ] or [ php ] and [/ php ] for PHP code, instead of [ quote ] and [/ quote ]

Thanks a lot ScallioXTX!

Learnt something from you now :slight_smile: