Hi knoak,
This question gets only interesting if species contains a hierachy,
like:
animals
birds
birds of pray
hawks
eagles
fishes
mamals
sea mamals
orca's
whales
The hierarchy uses a recursive foreign key equal to the key of the more
generic species group (which is in the same table as the more specific
ones).
Suppose the system is used by a field biologist, there may be another
table holding the numbers of the rings and tags, together with some
descriptive data like date of tagging, gender, coloring, size etc., and
of course a foreign key equal to the key of the most exact species the
tagged animal belongs to. Now we want to know the number of a higer
species group (for example birds) that where tagged after a certain
date. The code should work for a hierarchy of species of arbitrary depth
and any species (group). You can use any combination of SQL and php
code, but it should still perform reasonbly on a single processor off
the shelve server for about 10.000 species in an up to 10 deep
hierarchy. You can add some recursion into the data structure, but not
store the total number of tags per species group in the database.
Have fun!
Henk Verhoeven,
MetaClass.
knoak wrote:
Hi there,
I'm building a website about animals.
There is a mySQL DB behind it.
There are 2 tables: 1 - species
2 - animals
Species could be: birds, fishes etc.
Animals would be: hawk, eagle etc, and orca, whale etc.
So every animal belongs to one of the species.
Anyway, there is an admin part to delete or edit animals or entire
species.
You get an overview of all the species, and behin it is a number of
how much animals there are in it.
I calculated them as following:
(Query to get species){
$species_name=$query['name'];
$count_animals = mysql_query("SELECT COUNT(*) FROM animals WHERE
sort_of_species=$species_name");
$total_animals_in_species = mysql_result($count_total_items, 0);
echo $species_name." amount=".$total_animals_in_species;
}
To make a long story short, for each positive result in the
"get-species-query" i run another one to count the animals inside.
is this heavy for the server/DB, is there a better way to do this?
Sorry for the long story, i hope it's clear...
Thanks in advance.
greetings knoakske