seems no prob with ur code - don't know...
maybe you should check echoing $catids value after it is assigned (in get_tag_data) and after return to get_tag_cloud function to see if the id value is there
tag cloud code
//this line is wrong im guessing
$catids = $row['autoid'];
$catids should be $catids[], if you're trying to automatically assign them into an array.
I can't figure it out
It seems like this below connects the category name and the number of entries for the category, I just need to connect the actual category ID number to this value as well somehow
<?PHP
$arr[$row['category_name']] = $row['count'];
?>
you could do something like
$arr[$row['category_name']] = array('count' => $row['count'], 'id' => $row['autoid']);
Given an entry of:
auto_id: 5
count: 400
category_name: foo
it would return an array like:
$arr[foo] = array('count' => 400, 'id' => 5);
not having any luck =(
Fatal error: Unsupported operand types in /home/friend/public_html/sandbox/blog.php on line 22
Here is full code for testing file
<?PHP
include "../config/functions.inc.php";
function get_tag_data() {
$sqltag = "SELECT * FROM friend_blog_category GROUP BY category_name ORDER BY count DESC";
$resultSelect= executequery($sqltag);
while($row = mysql_fetch_array($resultSelect)) {
$arr[$row['category_name']] = array('count' => $row['count'], 'id' => $row['autoid']);
//$arr[$row['category_name']] = $row['count'];
}
ksort($arr);
return $arr;
}
function get_tag_cloud() {
// Default font sizes
$min_font_size = 12;
$max_font_size = 30;
// Pull in tag data
$tags = get_tag_data();
$minimum_count = min(array_values($tags));
$maximum_count = max(array_values($tags));
$spread = $maximum_count - $minimum_count;
if($spread == 0) {
$spread = 1;
}
$cloud_html = '';
$cloud_tags = array(); // create an array to hold tag code
foreach ($tags as $tag => $count) {
$size = $min_font_size + ($count - $minimum_count)
* ($max_font_size - $min_font_size) / $spread;
$cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' . '" class="tag_cloud" href="?action=bloghome&type=blog&category=' . $catids . '" title="\'' . $tag . '\' returned a count of ' . $count . '">' . htmlspecialchars(stripslashes($tag)) . '</a>';
}
$cloud_html = join("\n", $cloud_tags) . "\n";
return $cloud_html;
}
print get_tag_cloud();
?>
anyone have any ideas how to do this?
I can't tell what's wrong with your code, but chances are you're going to want to restructure the way you handle data coming out of the database. Right now you're kind of mashing together a couple different suggestions and it may not be the best - you'll want to re-write it cleanly, in my opinion.
It could be your use of min(array_values() and max(array_values(), seeing as we've changed the initial array it's referencing. We added a sub-array, so you'll want to adjust for that, I think.
yeah code is just from an online tutorial to build a tag cloud, If I cannot get it to work I will just have to build a giant switch statement to take the name of category and convert it to the category ID for links
Did you try changing the min() and max() lines like I said? I'm pretty sure that's causing problems with the way we've changed the array.
Horizon88 wrote:Did you try changing the min() and max() lines like I said? I'm pretty sure that's causing problems with the way we've changed the array.
Honestly I don't understand it enough to change them
Heres what I do, maybe it would be of some help to you.
<?php
// connect to database at some point
// In the SQL below, change these three things:
// thing is the column name that you are making a tag cloud for
// id is the primary key
// my_table is the name of the database table
$query = "SELECT date AS tag, COUNT(id) AS quantity
FROM my_table
GROUP BY date
ORDER BY date DESC";
$result = mysql_query($query);
// here we loop through the results and put them into a simple array:
// $tag['thing1'] = 12;
// $tag['thing2'] = 25;
// etc. so we can use all the nifty array functions
// to calculate the font-size of each tag
//while ($row = mysql_fetch_array($result)) {
while ($row = mysql_fetch_array($result)) {
$tags[$row['day']] = $row['quantity'];
}
// change these font sizes if you will
$max_size = 250; // max font size in %
$min_size = 100; // min font size in %
// get the largest and smallest array values
$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;
}
// determine the font-size increment
// this is the increase per tag quantity (times used)
$step = ($max_size - $min_size)/($spread);
// loop through our tag array
foreach ($tags as $key => $value) {
// calculate CSS font-size
// find the $value in excess of $min_qty
// multiply by the font-size increment ($size)
// and add the $min_size set above
$size = $min_size + (($value - $min_qty) * $step);
// uncomment if you want sizes in whole %:
// $size = ceil($size);
// you'll need to put the link destination in place of the #
// (assuming your tag links to some sort of details page)
echo '<a href="index.php?id='.$key.'" style="font-size: '.$size.'%"';
// perhaps adjust this title attribute for the things that are tagged
echo ' title="'.$value.' things tagged with '.$key.'"';
echo '>'.$key.'</a> ';
// notice the space at the end of the link
}
?>