CodeIgniter Forums
Create a tag cloud (kind of) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Create a tag cloud (kind of) (/showthread.php?tid=13184)

Pages: 1 2


Create a tag cloud (kind of) - El Forum - 11-13-2008

[eluser]iDenta[/eluser]
Hello,

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

Thanks!


Create a tag cloud (kind of) - El Forum - 11-13-2008

[eluser]simonmaddox[/eluser]
Doing a query similar to this might help:

Code:
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


Create a tag cloud (kind of) - El Forum - 11-13-2008

[eluser]Xeoncross[/eluser]
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).


Create a tag cloud (kind of) - El Forum - 11-13-2008

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


Create a tag cloud (kind of) - El Forum - 11-13-2008

[eluser]iDenta[/eluser]
Hi!

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:

table
- column (words)

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

posts
- id
- title
- body

tags
- id
- name

posts_tags
- post_id
- tag_id

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


Create a tag cloud (kind of) - El Forum - 11-13-2008

[eluser]drewbee[/eluser]
this is taken care of by a simple query
Code:
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.


Create a tag cloud (kind of) - El Forum - 11-13-2008

[eluser]iDenta[/eluser]
Thanks drewbee, i will try that.

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


Create a tag cloud (kind of) - El Forum - 11-14-2008

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

Code:
$db->select('word_list, COUNT(word_list) AS total', FALSE);
$db->group_by('word_list');
$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.


Create a tag cloud (kind of) - El Forum - 11-14-2008

[eluser]iDenta[/eluser]
That worked perfectly!

I also tried:

Code:
$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:

Code:
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?


Create a tag cloud (kind of) - El Forum - 11-14-2008

[eluser]davidbehler[/eluser]
Try this instead:
Code:
foreach ($tag->result() as $row)
{
    echo $row->word_list;
    echo $row->total;
}

That should give you the words on the corresponding count.