I have been looking for a ‘simple’ tag cloud generator that will parse content from MySQL for ages and couldn’t find one. So I adapted – and heavily modified (reduced) – and CSS’d – the best one that I could find. It turned out nice and simple.
.size9 { color: #000; font-size: 26px; }
.size8 { color: #111; font-size: 24px; }
.size7 { color: #222; font-size: 22px; }
.size6 { color: #333; font-size: 20px; }
.size5 { color: #444; font-size: 18px; }
.size4 { color: #555; font-size: 16px; }
.size3 { color: #666; font-size: 14px; }
.size2 { color: #777; font-size: 12px; }
.size1 { color: #888; font-size: 8px; }
.size0 { color: #999; font-size: 6px; }
$maximum) $maximum = $count;
//create array
$elements[] = array('word' => $word, 'count' => $count);
}
//random
//shuffle($elements);
//alphabetical
sort($elements);
foreach ($elements as $e){ // start looping through the tags
// determine the popularity of this term as a percentage
$percent = floor(($e['count'] / $maximum) * 100);
// determine the class for this term based on the percentage
if ($percent >= 99) $class = 9;
elseif ($percent >= 70) $class = 8;
elseif ($percent >= 60) $class = 7;
elseif ($percent >= 50) $class = 6;
elseif ($percent >= 40) $class = 5;
elseif ($percent >= 30) $class = 4;
elseif ($percent >= 20) $class = 3;
elseif ($percent >= 10) $class = 2;
elseif ($percent >= 5) $class = 1;
else $class = 0;
// output this term
//with links...
//echo "" . $k['term'] . "\n ";
//without links.../
echo "" . $e['word'] . "\n ";
}
// for debugging....
//echo "
";
//echo "";
//print_r($elements);
//echo "
";
?>