Jump to content

Recommended Posts

 

I am working on this tag cloud on my site. everything works great. Although I cant figure out how to display information as title tag in the link.

 

here is the code I am using, and this work fine.

 

function tag_info() { 
  $result = m_q("SELECT * FROM pic_tags GROUP BY tag ORDER BY RAND() LIMIT 20"); 
  while($row = mysql_fetch_array($result)) { 
    $arr[$row['tag']] = $row['count'];
  } 
  ksort($arr); 
  return $arr; 
}

function tag_cloud() {

    $min_size = 10;
    $max_size = 30;

    $tags = tag_info();

    $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();
    foreach ($tags as $tag => $count) {
        $size = $min_size + ($count - $minimum_count) 
            * ($max_size - $min_size) / $spread;
        $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
            . '" class="tag_cloud" href="tagedphoto.php?tag=' . $tag 
            . '"  returned a count of ' . $count . '  title="' . $description . '"    ">' 
            . htmlspecialchars(stripslashes($tag)) . '';
    }
    $cloud_html = join("\n", $cloud_tags) . "\n";
    return $cloud_html;

}

 

 

As you can see, I added the $description to the title tag within the link, although its not pulling the data from the database. I believe I have not defined it within the function, but Im not sure ...

 

any clue to whats going n here ?

 

thx

 

bobby

 

 

Link to comment
https://forums.phpfreaks.com/topic/119154-tag-cloud-help/
Share on other sites

try

<?php
function tag_info() { 
  $result = m_q("SELECT * FROM pic_tags GROUP BY tag ORDER BY RAND() LIMIT 20"); 
  while($row = mysql_fetch_array($result)) {
  	// add both data to returned array
    $arr[$row['tag']] = array($row['count'], $row['description']);
  } 
  ksort($arr); 
  return $arr; 
}

function tag_cloud() {

    $min_size = 10;
    $max_size = 30;

    $tags = tag_info();

    $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();
    foreach ($tags as $tag => $count) {
        $size = $min_size + ($count - $minimum_count) 
            * ($max_size - $min_size) / $spread;
        //change output to $count[0](count) and $count[](description)
        //add ending a tag
        $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
            . '" class="tag_cloud" href="tagedphoto.php?tag=' . $tag 
            . '">  returned a count of ' . $count[0] . '  title="' . $count[1] . '"    ">' 
            . htmlspecialchars(stripslashes($tag)) . '</a>';
    }
    $cloud_html = join("\n", $cloud_tags) . "\n";
    return $cloud_html;
}
?>

not tested

Link to comment
https://forums.phpfreaks.com/topic/119154-tag-cloud-help/#findComment-613599
Share on other sites

change lines

    $tags = tag_info();

    $minimum_count = min(array_values($tags));
    $maximum_count = max(array_values($tags));

to

$tags = tag_info();
foreach ($tags as $t) $tags1[] = $t[0];
$minimum_count = min($tags1);
$maximum_count = max($tags1);

Link to comment
https://forums.phpfreaks.com/topic/119154-tag-cloud-help/#findComment-613791
Share on other sites

ok this is what I have ....

 

function tag_info() { 
  $result = m_q("SELECT * FROM pic_tags GROUP BY tag ORDER BY RAND() LIMIT 20"); 
  while($row = mysql_fetch_array($result)) {
  	// add both data to returned array
    $arr[$row['tag']] = array($row['count'], $row['desc']);
  } 
  ksort($arr); 
  return $arr; 
}

function tag_cloud() {

    $min_size = 10;
    $max_size = 30;

    $tags = tag_info();

foreach ($tags as $t) $tags1[] = $t[0];
$minimum_count = min($tags1);
$maximum_count = max($tags1);

    $spread = $maximum_count - $minimum_count;

    if($spread == 0) {
        $spread = 1;
    }

    $cloud_html = '';
    $cloud_tags = array();
    foreach ($tags as $tag => $count) {
        $size = $min_size + ($count[0] - $minimum_count) 
            * ($max_size - $min_size) / $spread;
        //change output to $count[0](count) and $count[](description)
        //add ending a tag
        $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
            . '" class="tag_cloud" title=" '. $desc .'   " href="tagedphoto.php?tag=' . $tag 
            . ' ">' 
            . htmlspecialchars(stripslashes($tag)) . '</a>';
    }
    $cloud_html = join("\n", $cloud_tags) . "\n";
    return $cloud_html;
}


but its not showing the description i have in the database for the variable  $desk
( i currently only have 1 description inputed in the database, its for the tag AWARD WINNING )

this is the page where the tag cloud is : http://franklinspirko.com/sites/dwf/index.php

 

 

Link to comment
https://forums.phpfreaks.com/topic/119154-tag-cloud-help/#findComment-614035
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.