[Zope] Probably Dumb Question re count(*)

Matt Goodall m.g.goodall@ntlworld.com
29 Dec 2001 21:00:50 +0000


Hi,

Change the "countrecords" SQL method to

    select count(*) as num_records from xyz

so that you know the name (num_records) of the column. Then use the
following to display that count:

    <dtml-var "countrecords()[0]['num_records']">

The DTML is simply getting the column named num_records from the 1st row
of the result set.

Cheers, Matt

On Sat, 2001-12-29 at 20:32, Dan Shafer wrote:
> I know this has to be easy but my eyes are bloody from looking for 
> the answer at zope.org and in the Zope docs.
> 
> I want to have a sentence on a page that simply tells people how many 
> records are in a database. I created a ZSQL method that just does 
> this:
> 
> select count(*) from database1
> 
> That method is called countrecords.
> 
> Now in the DTML document, I have:
> 
> There are <dtml-var countrecords> records in the database.
> 
> No joy. No value ever gets placed into the sentence.
> 
> So I suspect that the count is being returned as a list (which is how 
> SQL results are supposed to be returned to Zope/Python, a I get it). 
> But here, there's no row and there's no variable name, so how would I 
> possibly iterate over it?
> 
> Is there an easier, more direct way to do this? I'm sure there is but 
> I can't find a single example of this use anywhere.
> -- 
> Dan Shafer, Author-Consultant
> http://www.danshafer.com
> http://www.shafermedia.com
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )