"I couldn't see the point in a separate tags table" What about 2 articles that share the same tags? You run the risk of tagging either with "one" or "1" (for example) or "CakePHP", "cakephp", "Cakephp", "cakePHP"...
There's an awful lot of processing happening in your foreach loop. What happens when you get 10,000 records? or 100,000? A relational database eats this kind of aggregation for breakfast :-) On Jan 19, 4:20 pm, leo <[email protected]> wrote: > I couldn't see the point in a separate tags table, so I have a tags > column on the table that requires it. > > To retrieve the tags and tag count, I do this: > > function getTagsWithCounts($conditions = array()) > { > // Return assoc_array(tags) for all records in > database. Keyed on tagword, > // value = tagcount > > $tagCounts = array(); > $tagRows = $this->findAll($conditions, 'tags'); > > foreach ($tagRows as $row): > $tags = explode(',',$row['Event']['tags']); > foreach ($tags as $tag): > $tag = trim($tag); > if (array_key_exists($tag, $tagCounts)): > $tagCounts[$tag]++; > else: > $tagCounts[$tag] = 1; > endif; > endforeach; > endforeach; > return $tagCounts; > } > > It's simple and it is working on two commercial sites, soon to be four. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
