[Zope] limiting no. of records retrieved

Eric Walstad eric@walstads.net
Sun, 18 Aug 2002 09:11:42 -0700


Hi Greg,
Look into Zope's batching mechanism in the docs.  Using <dtml-in> or 
tal:repeat you will be able to do what you want without LIMITing your 
MySQL query.
Otherwize, you might try making two calls to your MySQL table, one using 
LIMIT and one using COUNT(field_name) without LIMIT.
Good luck,
Eric.

PS, here's a DTML example from:
http://www.zope.org/Products/examples/view_source

<dtml-in name="results" size="batch_size" start="query_start">
   <dtml-if name="sequence-start">
     <dtml-var name="document_title"> Products
       <dtml-var name="sequence-number">
   </dtml-if>
   <dtml-if name="sequence-end">
     -<dtml-var name="sequence-number"> of <dtml-var expr="_.len(results)">
   </dtml-if>
</dtml-in>


Where "results" would be the results of your ZSQL mthod call.


Greg Conway wrote:
> Hi all,
> 
> I've been trying to limit the no. of records retrieved by a MySQL query.
> 
> I've managed to do this, using LIMIT, and have built this into my Zope app,
> but....
> 
> How can I retrieve the number of records that would have been retrieved if I
> hadn't limited the Query?
> 
> So I can display something like 'display records 1 - 30 of 250', if you see
> what I mean.
> 
> The MySQL documentation tells me I can do it using the FOUND_ROWS()
> command - if I am using version 4.0 + of MySQL! which I am not.
> 
> So, is there a way of achieving this in Zope? Seeing as it's so cool at
> everything else!!
> 
> Many thanks for any help!
> 
> Regards,
> 
> Greg Conway.