I've looked everywhere and I think this should be simple but I'm not getting it I simply want to count the number of records generated by an ZSQL Method (SQL query) within a DTML Method (something like get the record count of that certain query). I then want to refer to this number (could be zero if there are no records) and say if this number is zero then do something, else do something else. Can anyone help??
Why don't you let the query itself count the record? e.g. select count(*) as tcount from sometable where somecolumn='somevalue' DTML is not really the right toolfor this job, SQL is! ----- Original Message ----- From: "Sheree Beaudette" <sheree@psouth.net> To: <zope@zope.org> Sent: Wednesday, July 25, 2001 9:35 PM Subject: [Zope] Simple, I think!
I've looked everywhere and I think this should be simple but I'm not getting it
I simply want to count the number of records generated by an ZSQL Method (SQL query) within a DTML Method (something like get the record count of that certain query). I then want to refer to this number (could be zero if there are no records) and say if this number is zero then do something, else do something else.
Can anyone help??
_______________________________________________ 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 )
[Phil Harris]
Why don't you let the query itself count the record?
e.g.
select count(*) as tcount from sometable where somecolumn='somevalue'
You don't want to do this, because either you have to go to the database twice - once for the data and once for the count - or you have to return the count for each row which is annoying at least.
DTML is not really the right toolfor this job, SQL is!
Sure it is. Just call the len() function on the result returned by the query: <dtml-let results=your_query_method> ===<dtml-var "_.len(results)">==== </dtml-let> I just tried it to confirm my memory, and it worked fine. Cheers, Tom P
You could do this: <dtml-let results="SQL_Select()"> #Results returned = <dtml-var "_.len(results)"> </dtml-let> Mark
I've looked everywhere and I think this should be simple but I'm not getting it
I simply want to count the number of records generated by an ZSQL Method (SQL query) within a DTML Method (something like get the record count of that certain query). I then want to refer to this number (could be zero if there are no records) and say if this number is zero then do something, else do something else.
Can anyone help??
_______________________________________________ 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 )
True enough you could, but why? SQL has the correct tools for the job! ----- Original Message ----- From: "Mark N. Gibson" <mark@kaivo.com> To: "Sheree Beaudette" <sheree@psouth.net> Cc: <zope@zope.org> Sent: Wednesday, July 25, 2001 10:16 PM Subject: Re: [Zope] Simple, I think!
You could do this:
<dtml-let results="SQL_Select()"> #Results returned = <dtml-var "_.len(results)"> </dtml-let>
Mark
I've looked everywhere and I think this should be simple but I'm not
getting
it
I simply want to count the number of records generated by an ZSQL Method (SQL query) within a DTML Method (something like get the record count of that certain query). I then want to refer to this number (could be zero if there are no records) and say if this number is zero then do something, else do something else.
Can anyone help??
_______________________________________________ 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 )
_______________________________________________ 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 )
True enough you could, but why?
SQL has the correct tools for the job!
True. So if you're only interested in the number, use SQL for performance. If you also want to display something from the same set, use DTML magic.
You could do this:
<dtml-let results="SQL_Select()"> #Results returned = <dtml-var "_.len(results)"> </dtml-let>
Mark
I've looked everywhere and I think this should be simple but I'm not
getting
it
I simply want to count the number of records generated by an ZSQL
Method
(SQL query) within a DTML Method (something like get the record count of that certain query). I then want to refer to this number (could be zero if there are no records) and say if this number is zero then do something, else do something else.
Can anyone help??
_______________________________________________ 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 )
_______________________________________________ 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 )
_______________________________________________ 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 )
On Wed, 25 Jul 2001, Sheree Beaudette wrote:
I've looked everywhere and I think this should be simple but I'm not getting it
I simply want to count the number of records generated by an ZSQL Method (SQL query) within a DTML Method (something like get the record count of that certain query). I then want to refer to this number (could be zero if there are no records) and say if this number is zero then do something, else do something else.
w/in the <dtml-in> loop, sequence-length holds this (not just for ZSQL, but for *all* sequences). So: <dtml-in allStaff> ... list each staff person ... <dtml-if sequence-end> we have <dtml-var sequence-length> staff members. </dtml-if> <dtml-else> <b>how strange</b>. we have no staff </dtml-in> -- Joel Burton <jburton@scw.org> Director of Information Systems, Support Center of Washington
participants (6)
-
Joel Burton -
Mark N. Gibson -
Peter Bengtsson -
Phil Harris -
Sheree Beaudette -
Thomas B. Passin