Currently I am using commas “,” to save tags as text and when I neeed them to process and use somewhere I need to explode the string e.g. “usa,canada,crime,Toronto,music,fall”.
I was thinking if there is any better way ( less resource and time-consuming friendly ) of doing this tag or is this the only solution that everybody use.
EDIT:
I have a small project, without tags managment in admin. I do not need to have three tables just for tags in db. I am just looking for some more clever solution how to save and explode the tags from the saved strings in the database.
Use the three-table approach, really! Really really!
Otherwise, how will you query items that have tag “usa” without also getting items tagged with “usable”?
LIKE %usa%will return both.See this for a discussion on three methods for implementing tags in db:
http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html
EDIT in response to comment:
Commas won’t help won’t help won’t help. Example tag field:
culture,usa. How will youLIKEthis?You could arguably save tags in format:
,culture,usa,(stating and ending with a comma).Imho that will bring along some special cases and it will in the end become more complicated that the three-table approach.