<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: Adding tagging to my php CMS</title>
	<link>http://ask.metafilter.com/34897/Adding-tagging-to-my-php-CMS/</link>
	<description>Comments on Ask MetaFilter post Adding tagging to my php CMS</description>
	<pubDate>Wed, 22 Mar 2006 14:08:49 -0800</pubDate>
	<lastBuildDate>Wed, 22 Mar 2006 14:08:49 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: Adding tagging to my php CMS</title>
		<link>http://ask.metafilter.com/34897/Adding-tagging-to-my-php-CMS</link>	
		<description>Whats the best way to setup and implement a tagging/folksonomy system into a php content management system from scratch? &lt;br /&gt;&lt;br /&gt; I use a custom php based content management system at my work and i&apos;m wondering what what the best way to set up a tagging/folksonomy type system like the ones you see here and delisous, etc. i&apos;m building it into my system by hand, but i&apos;d really like some advice on where to start, such as table structure, useful functions, etc.&lt;br&gt;
&lt;br&gt;
I appreciate any help, this has been a difficult thing to google for.</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2006:site.34897</guid>
		<pubDate>Wed, 22 Mar 2006 13:51:49 -0800</pubDate>
		<dc:creator>yeahyeahyeahwhoo</dc:creator>
		
			<category>webprogramming</category>
		
			<category>php</category>
		
			<category>folksonomy</category>
		
	</item> <item>
		<title>By: mathowie</title>
		<link>http://ask.metafilter.com/34897/Adding-tagging-to-my-php-CMS#543650</link>	
		<description>It&apos;s super easy actually.&lt;br&gt;
&lt;br&gt;
You have a tags table in your db, and it should have fields for tag_name and parent_id at the very least. The parent_id corresponds to whatever you are associating tags with, be they single pages, blog posts, whatever.&lt;br&gt;
&lt;br&gt;
Then you create a form to add tags however you want (flickr style, or make them like yahoo&apos;s myweb) and associate them with your parent_ids when adding new content or editing old content.&lt;br&gt;
&lt;br&gt;
Finally, you just display them on the appropriate page where parent_id = foo and you grab all tag_name items with parent_id = foo.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34897-543650</guid>
		<pubDate>Wed, 22 Mar 2006 14:08:49 -0800</pubDate>
		<dc:creator>mathowie</dc:creator>
	</item><item>
		<title>By: jellicle</title>
		<link>http://ask.metafilter.com/34897/Adding-tagging-to-my-php-CMS#543688</link>	
		<description>&lt;a href=&quot;http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html&quot;&gt;Here&apos;s your answer&lt;/a&gt;.&lt;br&gt;
&lt;br&gt;
There are some tricky bits because of the limitations of SQL.  Tradeoffs, if you will.  If you want to allow infinite tags per piece of content, you have to set up the database like so.  If you can limit the number of tags, you can set it up like so.  If the query has to be fast, you have to set up the database like so, if it doesn&apos;t, you can set it up like so.  And so on.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34897-543688</guid>
		<pubDate>Wed, 22 Mar 2006 14:36:55 -0800</pubDate>
		<dc:creator>jellicle</dc:creator>
	</item><item>
		<title>By: Rhomboid</title>
		<link>http://ask.metafilter.com/34897/Adding-tagging-to-my-php-CMS#543844</link>	
		<description>Yikes.  The &quot;MySQLicious&quot; schema in that link is just horrid.  By all means do not pick that one.  The &quot;Toxi&quot; one (which displays actual knowledge of how SQL is supposed to work) is your best bet.  Don&apos;t let the fact that whoever wrote that summary is apparently database-clueless (&quot;I couldn&apos;t come up with an easy MySQL-query..&quot; --WTF?) cloud your judgement.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34897-543844</guid>
		<pubDate>Wed, 22 Mar 2006 17:00:28 -0800</pubDate>
		<dc:creator>Rhomboid</dc:creator>
	</item><item>
		<title>By: beerbajay</title>
		<link>http://ask.metafilter.com/34897/Adding-tagging-to-my-php-CMS#543946</link>	
		<description>Ditto Rhomboid. That person is an idiot; don&apos;t listen to them. There&apos;s no good reason to cram all the tags in one field. Parse the user input, ffs.&lt;br&gt;
&lt;br&gt;
You shouldn&apos;t need to fulltext search the tags unless you are beholden to the whims of ridiculous people like librarians.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34897-543946</guid>
		<pubDate>Wed, 22 Mar 2006 18:38:00 -0800</pubDate>
		<dc:creator>beerbajay</dc:creator>
	</item><item>
		<title>By: philipp.keller</title>
		<link>http://ask.metafilter.com/34897/Adding-tagging-to-my-php-CMS#544159</link>	
		<description>The person who wrote that article is speaking.. :-)&lt;br&gt;
&lt;br&gt;
It surely depends on what you are trying to do. If you are are in a hurry and you are sure you&apos;ll never get more than 1000 entries then I still think you should take the most simple &quot;MySQLicious&quot; approach. That is completely denormalized and yeah, not optimized by any mean (as Rhomboid said), it&apos;s the &quot;quick and dirty&quot; solution. You won&apos;t have many options. Building a tag cloud with this solution is quite difficult as you don&apos;t see how often a tag is used.&lt;br&gt;
&lt;br&gt;
We recently added tags to our CMS and we took the &quot;toxi&quot; solution, this is 3NF, the way you learnt it in school. You can have multiword tags and everything you like. You have to deal with tag orphans. Overall you have to invest some time and thoughts into implementing your tag schema this way but it&apos;s worth it.&lt;br&gt;
&lt;br&gt;
If you&apos;re building middle-scale application (up to 1 million items), &lt;a href=&quot;http://www.pui.ch/phred/archives/2005/06/tagsystems-performance-tests.html&quot;&gt;performance wise&lt;/a&gt; you best pick the toxi or the mysqlicious solution with MySQL fulltext search.&lt;br&gt;
If you want to build a bigger app, then you have to mix in non-RDBMS-systems like &lt;a href=&quot;http://lucene.apache.org/java/docs/&quot;&gt;Lucene&lt;/a&gt;.&lt;br&gt;
&lt;br&gt;
Yes, speaking about minus-queries (like &quot;I want to see all posts tagged &apos;fruit&apos; and &apos;vegetable&apos; but not &apos;apple&apos;&quot;) I wrote &quot;I couldn&apos;t cdome up with an easy MySQL-query&quot;: I still cannot think of an easy way to solve this. I would have to do two separate queries one for the &quot;wanted&quot; tags and one for the &quot;unwanted&quot; tags and then would have to join these together. This would be very slow I guess.&lt;br&gt;
Can &lt;strong&gt;you&lt;/strong&gt; come up with a good query?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34897-544159</guid>
		<pubDate>Wed, 22 Mar 2006 23:30:12 -0800</pubDate>
		<dc:creator>philipp.keller</dc:creator>
	</item><item>
		<title>By: Rhomboid</title>
		<link>http://ask.metafilter.com/34897/Adding-tagging-to-my-php-CMS#544172</link>	
		<description>&lt;blockquote&gt;&lt;small&gt;&lt;i&gt;Yes, speaking about minus-queries (like &quot;I want to see all posts tagged &apos;fruit&apos; and &apos;vegetable&apos; but not &apos;apple&apos;&quot;) I wrote &quot;I couldn&apos;t cdome up with an easy MySQL-query&quot;: I still cannot think of an easy way to solve this. I would have to do two separate queries one for the &quot;wanted&quot; tags and one for the &quot;unwanted&quot; tags and then would have to join these together. This would be very slow I guess.&lt;br&gt;
Can you come up with a good query?&lt;/i&gt;&lt;/small&gt;&lt;/blockquote&gt;&lt;/small&gt;&lt;/i&gt;How about:&lt;pre&gt;SELECT b.*&lt;br&gt;FROM tagmap bt, bookmark b, tag t&lt;br&gt;WHERE bt.tag_id = t.tag_id&lt;br&gt;AND (t.name IN (&apos;fruit&apos;, &apos;vegetable&apos;))&lt;br&gt;AND b.id = bt.bookmark_id&lt;br&gt;AND t.tag_id NOT IN (SELECT tag_id FROM tag WHERE name = &apos;apple&apos;)&lt;br&gt;GROUP BY b.id&lt;br&gt;HAVING COUNT( b.id )=2&lt;/pre&gt;MySQL has had subqueries since 4.1, released  2003-04-09 -- nearly three years ago! The people that refuse to use &quot;real&quot; database features like subqueries in MySQL because they&apos;re stuck in the stone age of 3.whatever are the same people that give MySQL a bad name for being a toy database.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34897-544172</guid>
		<pubDate>Thu, 23 Mar 2006 00:03:52 -0800</pubDate>
		<dc:creator>Rhomboid</dc:creator>
	</item><item>
		<title>By: philipp.keller</title>
		<link>http://ask.metafilter.com/34897/Adding-tagging-to-my-php-CMS#544176</link>	
		<description>Rhomboid: Thanks! I confess I&apos;m stuck in the stone age of 3.whatever and therefore confess that I&apos;m &quot;database-clueless&quot; :-)&lt;br&gt;
I&apos;ll add this to my article if you don&apos;t mind?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34897-544176</guid>
		<pubDate>Thu, 23 Mar 2006 00:08:21 -0800</pubDate>
		<dc:creator>philipp.keller</dc:creator>
	</item><item>
		<title>By: Rhomboid</title>
		<link>http://ask.metafilter.com/34897/Adding-tagging-to-my-php-CMS#544179</link>	
		<description>Hum, that is bogus... I spoke too soon.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34897-544179</guid>
		<pubDate>Thu, 23 Mar 2006 00:14:10 -0800</pubDate>
		<dc:creator>Rhomboid</dc:creator>
	</item><item>
		<title>By: Rhomboid</title>
		<link>http://ask.metafilter.com/34897/Adding-tagging-to-my-php-CMS#544185</link>	
		<description>I think this is closer to what you want, although I didn&apos;t test it:&lt;pre&gt;SELECT b.*&lt;br&gt;FROM bookmark b, tagmap bt, tag t&lt;br&gt;WHERE b.id = bt.bookmark_id AND bt.tag_id = t.tag_id&lt;br&gt;AND (t.name IN (&apos;fruit&apos;, &apos;vegetable&apos;))&lt;br&gt;AND b.id NOT IN (SELECT id FROM bookmark b, tagmap bt, tag t&lt;br&gt;                 WHERE b.id = bt.bookmark_id AND bt.tag_id = t.tag_id AND t.name = &apos;apple&apos;)&lt;br&gt;GROUP BY b.id&lt;br&gt;HAVING COUNT( b.id )=2&lt;/pre&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34897-544185</guid>
		<pubDate>Thu, 23 Mar 2006 00:24:36 -0800</pubDate>
		<dc:creator>Rhomboid</dc:creator>
	</item><item>
		<title>By: Rhomboid</title>
		<link>http://ask.metafilter.com/34897/Adding-tagging-to-my-php-CMS#544186</link>	
		<description>Might have to use &quot;b.id&quot; instead of just &quot;id&quot; in the SELECT in the subquery.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34897-544186</guid>
		<pubDate>Thu, 23 Mar 2006 00:26:48 -0800</pubDate>
		<dc:creator>Rhomboid</dc:creator>
	</item><item>
		<title>By: philipp.keller</title>
		<link>http://ask.metafilter.com/34897/Adding-tagging-to-my-php-CMS#544192</link>	
		<description>Yeah, this looks like it would work. I&apos;ll test it and then will add this to the article. Thanks for helping out!</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34897-544192</guid>
		<pubDate>Thu, 23 Mar 2006 00:36:20 -0800</pubDate>
		<dc:creator>philipp.keller</dc:creator>
	</item><item>
		<title>By: yeahyeahyeahwhoo</title>
		<link>http://ask.metafilter.com/34897/Adding-tagging-to-my-php-CMS#544328</link>	
		<description>i thought that article was awesome for someone like me that wasnt shat out of the womb knowing all there is to know about database schemas, thats for the help folks.&lt;br&gt;
&lt;br&gt;
what i had drawn up previously was closer to the mysqlicious deal but i can really see the sexiness in the 3 tables. performance isnt a huge issue but i&apos;d rather tackle it now.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34897-544328</guid>
		<pubDate>Thu, 23 Mar 2006 05:51:57 -0800</pubDate>
		<dc:creator>yeahyeahyeahwhoo</dc:creator>
	</item>
	</channel>
</rss>
