Jump to content

[SOLVED] Query containing EXPLODE for tag cloud?


kingnutter

Recommended Posts

Hi everyone,

 

I am trying to create a tag cloud from all rows of field 'moj_genre' in table 'mojocd' which contains tags separated by commas, splitting them all up in one neat query.

 

I have written the query below in hybrid MySql/English. Is this possible and, if so, what would be the correct syntax?

 

"SELECT moj_genre FROM mojocd ***EXPLODE moj_genre on comma*** GROUP BY ***EXPLODEd results of moj_genre*** ORDER BY count DESC"

Link to comment
Share on other sites

Cheers. I'm not having much luck Googling this.

 

How does a tag table work? (This is where I got stuck on a previous project)

 

I am thinking that the field in my entry form should be the same as present (tags split by commas). I then split this into an array to enter into the tags table.If DISTINCT it creates a new entry but what happens to a duplicate tag? Is another instance created reffing a project_id? Or is there only one instance of each tag each having an expandable array of project_ids?

 

Just a pointer to a good tutorial would be really helpful.

 

Thanks.

Link to comment
Share on other sites

You would have a table of tags.

 

[pre]

id      name

1      food

2      drink

3      car

[/pre]

 

Then a table of articles.

[pre]

id      title

1      sandwhich

2      fish with wine

3      eggs benadict

4      audi

[/pre]

 

Then, a table to join them.

[pre]

id      tag_id      article_id

1          1                1

2          1                2

3          2                2

4          3                3

[/pre]

 

Its a horrible example (its real late here) but can you see the relationships? Notice that article number 2 (fish with wine) has two tags? Both food and drink.

Link to comment
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.