Hi
I am trying to create a Tag Cloud from my database. Under my database for Tags, the words are separated by commas, so I am trying to split it as individual word by eliminating the commas but it does not seem to work. Any idea what is wrong with my code?
Code:
<?php
$query = "SELECT Tags AS Tag, COUNT(ID) AS quantity
FROM post_video
GROUP BY Tags
ORDER BY Tags DESC LIMIT 50";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$temp_Tags = explode(',', $row['Tags']);
foreach ($temp_Tags as $Tags) {
if (isset($Tags[$Tag])) {
$Tags[$Tag]++;
} else {
$Tags[$Tag] = 1;
}
}
$Tags[$row['Tag']] = $row['quantity'];
$category_id[$row['Tag']] = $row['category_id'];
}
$max_size = 250; // max font size in %
$min_size = 100; // min font size in %
$max_qty = max(array_values($Tags));
$min_qty = min(array_values($Tags));
// find the range of values
$spread = $max_qty - $min_qty;
if (0 == $spread) { // we don't want to divide by zero
$spread = 1;
}
$step = ($max_size - $min_size)/($spread);
// loop through our tag array
foreach ($Tags as $key => $value) {
$size = $min_size + (($value - $min_qty) * $step);
echo '<a href="index.php?cat_id='.$category_id[$key].'"
style="font-size: '.$size.'%"
title="'.$value.' things tagged with '.$key.'">'
.$key.'</a> ';
}
?>
Any help is greatly appreciated.