Blog demo, how to generate tags table

Hello,

To make it as simple as possible to understand I’ve divided the thread into question and summary, all I’m after is the dummy algorithm to perform the task and not the actual codings

Question,

Based on Blog demo application, you have just migrated bunch of posts into the database (each post has it’s defined tags already inside it’s correspondent tag field), now you want to generate the separate ‘tag’ table, you need to calculate repeated tags within all posts and generate frequency, then insert each unique tag with it’s frequency number into ‘tags’ table

How would you go about doing this?

Summary:

I’ve started to migrate my database of entries from an old system to the new one I’m just making based on Blog demo application, migration is going well so far and while migrating I’ve started to generate Tags for each entry, calculating the frequency of these tags and entering them into the separate db table of tags (while running the migration) appeared to be impossible since my loop became so nested and migration script became extremely slow so I decided to migrate the entries and then deal with the tag table generation

Appreciate your time

Nick

Solved,

array_count_values($MyArray) was what i needed

e.g.

posts table


id tags

1 apple, banana, orange

2 orange, banana

3 banana, kiwi

tags table


id tag frequency

export merged tags from posts table into an array

$all_tags(apple, banana mango, orange, orange, banana, banana, kiwi);

$frequencies = array_count_values($all_tags);

output:

Array

(

[apple] => 1

[banana] => 3

[orange] => 2

[kiwi] => 1

)