kaylie — 2010-05-02T04:23:52-04:00 — #1
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")
scallioxtx — 2010-05-02T05:11:07-04:00 — #2
$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 ]
kaylie — 2010-05-02T21:09:12-04:00 — #3
Thanks a lot ScallioXTX!
Learnt something from you now