Thread: Categorizing
View Single Post
Old Jan 17th, 2007, 5:45 PM   #5
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
A for loop with multiple insert statements. Presumably you're going to be reading from the database far more than writing to it, so a for-loop, though less efficient than a single insert query, seems the most efficient way overall.

You could set up a table to store all an animal's ancestor categories, I guess, something like:
ancestors(category_id, ancestor_id)

But that's just trading memory for CPU, and considering each animal is probably only going to belong to a relatively small group of categories, it's probably not worth it. Go with a for-loop and multiple inserts, would be my advice.
Arevos is offline   Reply With Quote