Results 1 to 6 of 6
May 24, 2012, 17:23 #1
- Join Date
- Jan 2012
- 0 Post(s)
- 0 Thread(s)
Counting Children in Database Query
I have a database that lists animal taxons - class, order, family, genus, species, etc. - in a parent-child relationship, like this...
(Field Taxon) (Field Parent)
I use the following query to display a list of each taxon's children, where $MyURL (e.g. www.mysite.com/Felidae) equals a value in the field Taxon.
$Children = mysql_query ("SELECT L.N, L.Taxon, L.Parent, L.Rank, G.Name_Common FROM gz_life AS L LEFT JOIN gz_names_genus AS G on G.Taxon = L.Taxon WHERE L.Parent = '$MyURL' Order By L.N, L.Rank");
Anyway, how can I display the NUMBER of children? For example, if there are six genera in the family Felidae, I might want to display something like Felidae (6).
Also, is there a way to display grand-children, or a complete sequence of children? I have navigation links that reach from the current taxon back to the animal kingdom, like this...
Animalia > Vertebrata > Mammalia > Carnivora > Felidae
It would be cool if I could type in Carnivora, and it would display the number of children (families) plus the number of grand-children (genera) and the number of great grand-children (species), like this...
Carnivora (26 families, 112 genera, 352 species)
Is there a way to do that?