I want to use implode() to store several into a mysql database like so tags=tag1,tag2,tag3 being separated by commas. I can easily do that but i am actually wondering how i could search the tag query to find a specify tag (ex. tag2). I read that i can use mysql LIKE but when i used it, it would only find the first tag in the string. If the tag i was looking for wasn't the first it would pick it up. Any help?

SpacePhoenix
—
2011-06-23T19:31:41Z —
#2

You'd be better off storing each tag in a separate row in the table. You'd probably need a "look-up" table as well. What's the current table structure that you've got?

Thread moved to MySQL forum

r937
—
2011-06-23T20:14:12Z —
#3

nlh205 said:

... wondering how i could search the tag query to find a specify tag (ex. tag2).

there is a way, using the FIND_IN_SET function, but i'll tell you up front that since the design of your table violates first normal form, a search query on the tags will require a table scan, and consequently your app will not scale, i.e. the more rows you have the slower the search gets

redesign the table and add a one-to-many tags table -- this can then be indexed, and your search query will finish in fractions of a second instead of fractions of an hour

nlh205
—
2011-06-23T23:17:59Z —
#4

r937 said:

redesign the table and add a one-to-many tags table -- this can then be indexed, and your search query will finish in fractions of a second instead of fractions of an hour

Would you be able to explain a little more as I only know the fair basics of mysql and i would rather use the most efficient way as you described.

nlh205
—
2011-06-23T23:59:20Z —
#5

Do you mean to start another table called tags for ex with the fields tag to store the tag name and another field `game_id' to store the game id that the tag corresponds too?

r937
—
2011-06-24T01:43:55Z —
#6

do me a favour and re-read post #1 -- i tried really hard but i couldn't see what kinds of things these tags are tagging -- recipes? jokes? photobombs? talking cats?

anyhow, that's the other half of the puzzle

i'll draft up a tags table for you as soon as you reveal a little more about what you're tagging

nlh205
—
2011-06-24T03:14:16Z —
#7

It's a flash game site. So it's a tag for a game (ex. racing or word). I already have games table to store the game info in but and i was going to store the tags as i posted originally(within the games table using implode). But i want to use the most efficient way. And thanks.