Zope
  Home arrow Zope arrow Page 5 - DTML Basics (part 3)
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ZOPE

DTML Basics (part 3)
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2002-07-02

    Table of Contents:
  • DTML Basics (part 3)
  • When In Rome...
  • A List In Time
  • An Easy Replacement
  • Bringing In The Database
  • Digging Deeper

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Dell PowerEdge Servers

    DTML Basics (part 3) - Bringing In The Database
    (Page 5 of 6 )

    Another common application of sequences involves using them in combination with database result sets to break up a large result set into smaller batches.

    Consider the following example, which invokes a ZSQL Method (for the uninitiated, a ZSQL Method is a special Zope object that allows you to communicate with a database - read more about it at (http://www.devshed.com/Server_Side/Zope/ZopeWithApache). In the following example, the GetUsers() method retrieves a list of users from a database

    select * from person
    as a sequence and uses a DTML loop to iterate through it and print the data.

    <table cellpadding="5" cellspacing="0" border="1" width="250"> <tr bgcolor="#CFCFCF"> <td align="left"><b>User Details</b></td> </tr> <dtml-in GetUsers sort=FirstName> <tr> <td align="left"><font size="2"><b><dtml-var sequence-number>. <dtml-var Title> <dtml-var FirstName> <dtml-var Surname></b></font><br> <font size="1"><i><dtml-var Email></i><br><dtml-var Tel><br><dtml-var Fax></font></td> </tr> </dtml-in> </table>
    The output displays all the records in a single page, as shown below.



    This example uses the <dtml-in> tag to loop over the result set returned by the GetUsers() ZSQL Method. The rest of the code is good ol' HTML to make the page look pretty.

    Depending on the number of records in the table, you can rest assured that this is a definite no-no as far as the usability and performance of the site is concerned. A better idea would be to split this result set into multiple "pages", so as to reduce overhead and also to make the site more usable. Here's the code:

    <table cellpadding="5" cellspacing="0" border="1" width="250"> <tr bgcolor="#CFCFCF"> <td align="left"><b>User Details</b></td> </tr> <dtml-in GetUsers size="6" start=start_here sort=FirstName> <dtml-if sequence-start> <dtml-if previous-sequence> <tr><td align="right"><font size="2">[ <a href="<dtml-var URL><dtml-var sequence-query>start_here=<dtml-var previous-sequence-start-number>"> Previous <dtml-var previous-sequence-size> users</a> ]</font></td></tr> <dtml-else> <tr><td align="right">&nbsp;</td></tr> </dtml-if> </dtml-if> <dtml-if sequence-even> <tr bgcolor="#DCDCDC"> <dtml-else> <tr bgcolor="#CECECE"> <tr> </dtml-if> <td align="left"><font size="2"><b><dtml-var sequence-number>. <dtml-var Title> <dtml-var FirstName> <dtml-var Surname></b></font><br> <font size="1"><i><dtml-var Email></i><br><dtml-var Tel><br><dtml-var Fax></font></td> </tr> <dtml-if sequence-end> <dtml-if next-sequence> <tr><td align="right"><font size="2">[ <a href="<dtml-var URL><dtml-var sequence-query>start_here=<dtml-var next-sequence-start-number>"> Next <dtml-var next-sequence-size> users</a> ]</font></td></tr> <dtml-else> <tr><td align="right">&nbsp;</td></tr> </dtml-if> </dtml-if> </dtml-in> </table>
    Phew! That's a lot of code...but the result is worth it.

    Take a close look at the output. No scroll bar. Neat little links to the next and previous "batch" of users. Just what I wanted.

    More Zope Articles
    More By Harish Kamath, (c) Melonfire


     

       

    ZOPE ARTICLES

    - Creating Zope Products
    - Plone Content Types With Archetypes
    - Flat User Management in Zope
    - Creating Basic Zope Applications
    - Getting started with Zope for Linux and Sola...
    - ZPT Basics (part 4)
    - ZPT Basics (part 3)
    - ZPT Basics (part 2)
    - ZPT Basics (part 1)
    - Exception Handling In DTML
    - DTML Basics (part 4)
    - DTML Basics (part 3)
    - DTML Basics (part 2)
    - DTML Basics (part 1)
    - Using Zope With Apache

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway