towards a tag cloud

So I wanted to include a tag cloud in the tweet nest page, the fastest was was building on top of this. Then I compiled a file to use with index page, here is the file and use the following command in the index.php in your tweetnest folder.

require “inc/preheader.php”;

tag_cloud.php:

<?php
$connection = mysql_connect("localhost", "root", "pass");
    $table="tweetnest";
    $words=array();
    $words_link=array();
    mysql_select_db($table,$connection);
    $query="SELECT `word`,`tweets`,null FROM `tn_words` where word<>'The' and word<>'are' and word<>'for' and  word<>'and' and word<>'that' and word<>'http' and word<>'you' and word<>'this' and word<>'with' order by tweets desc limit 100;";
 
    if($resultset=mysql_query($query,$connection)){
        while($row=mysql_fetch_row($resultset)){
            $words[$row[0]]=$row[1];
            $words_link[$row[0]]=$row[2];
        }
    }
// Incresing this number will make the words bigger; Decreasing will do reverse
$factor = 15;
 
// Smallest font size possible
$starting_font_size = 1;
 
// Tag Separator
$tag_separator = '&nbsp; &nbsp; &nbsp;';
$max_count = array_sum($words);
 foreach($words as $tag => $weight )
{
    $x = round(($weight * 100) / $max_count) * $factor;
    $font_size = $starting_font_size + $x.'px';
    if($words_link[$tag]=='NA') echo "<span style='font-size: ".$font_size."; color: #676F9D;'><a href='http://www.google.co.in/search?hl=en&q=".$tag."&meta='>".$tag."</a></span>".$tag_separator;
    else echo "<span style='font-size: ".$font_size."; color: #676F9D;'><a href='http://".$words_link[$tag]."/'>".$tag."</a></span>".$tag_separator;
}

?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s