Welcome Guest, Not a member yet? Register   Sign In
Create a tag cloud (kind of)


I'm trying to create something would look like a tag cloud, but i am not sure how to build it, since the table and so on structure is a little bit different then what you would use with FreeTag and such.

I have a table that contains a column with about 800 lines, and each line consist of a word. Now i wan't to count have many times each word occurs
in that column, and then present the results as a tag cloud. So that the most used word gets the biggest font, and so it goes on.

Now i'm kinda stuck, and don't really know how to do this with CI... The content of that column changes about 10 times a day, can that be a problem? Since it changes all the time, i probably have to check what words that are used, then count how many times they occur, and then try to create a tag cloud based on that...

So, does that make any sense? And if it does, any pointers on how to make it happend would be much appreciated Smile


Doing a query similar to this might help:

select tag, count(tag) as count from tags group by tag order by tags asc

You'll end up with "tag" and "count" for each row.
tag will hold the tag itself
count will hold the number of times it occurs

I built an awesome tagging system just for CodeIgniter. Check out my sig.

It not only handles cleaning,storing, searching, matching, and tagging - but it also supports as many tables as you need!

For example, you can tag your posts, your links, your users, your dog, and none of the tags will interfere with each other ("blue" for posts isn't the same as "blue" for users).

[eluser]Jose DueƱas[/eluser]
maybe this code igniter library could help you: Taggy
I'm using it in my projects, it's easy and works well.


Thank you for your fast reply.

I have taken a look at some of the tagging libraries like Taggy and such, but i get the feeling that they really can't do what i am looking for...

I think it is because of my tables are set up, i only got:

- column (words)

to work with... Most tagginglibraries seems to use something like:

- id
- title
- body

- id
- name

- post_id
- tag_id

Or am i missing something? I'm a newbie at PHP and CI, so maybe it's just me Smile

this is taken care of by a simple query
SELECT word_list, COUNT(word_list) AS total FROM words GROUP BY word_list

This will give you your each distinct word ONCE, along with the total times that the word occured.

Thanks drewbee, i will try that.

Just have to figure out how to convert it to Active Records Smile

I don't use active record for selecting (other then $db->query), however it would be something similar to this:

$db->select('word_list, COUNT(word_list) AS total', FALSE);
$query = $db->get('words');

As well, if their are errors is the above, I would expect it to be at the COUNT part. Thats the best I can do for you Big Grin Should give you a place to start though.

That worked perfectly!

I also tried:

$sql = "SELECT word_list, COUNT(word_list) AS total FROM words GROUP BY word_list";
$tag = $this->db->query($sql);

same results.

But i can't figure out how to present how many times each word occurs, tried presenting results with a loop:

foreach ($tag->result() as $row)
    echo $row->word_list;
    echo $tag->num_rows();

$tag->num_rows() seems to give me nr of unique words, COUNT('word_list') just presents "1".

What am i doing wrong?

Try this instead:
foreach ($tag->result() as $row)
    echo $row->word_list;
    echo $row->total;

That should give you the words on the corresponding count.

Theme © iAndrew 2016 - Forum software by © MyBB