[Zope-DB] return count() from mysql in zope

James R. Saker Jr. jsaker at americanrelay.com
Sat Sep 4 14:58:49 EDT 2004


I'd expect this should be an easy item, but apparently am not thinking
the right way yet. I want to have a summary page in my Zope site of
values from my connected MySQL database, e.g. number of animals in the
zoo, by animalTypeID.

For instance:

database: animals
table: animalTypes (pkID, animalName)

(1,"Lions")
(2,"Tigers")
(3,"Bears")

and in table: animals (pkID, animalTypeID FK-->animalTypes.pkID, name,
location)...

(1,1,"Simba","Cage #3")
(1,3,"Gentle Ben", "Cage #17")
(1,3,"Smokey", "Cage #44")
(1,2,"Tony", "Cafeteria")

if I want to get a count value, e.g. the total number of Bears, my SQL
query would be:

SELECT COUNT(pkID) FROM animals WHERE animalTypeID = 3;

Within Zope, I'm not sure whether to tackle this via DTML or via a
Python script. I've tried dtml-call and that's not working, as well as a
few other approaches and clearly am missing something obvious given how
easy this should be... ideas?

Jamie




More information about the Zope-DB mailing list