SunQuest
 
       Zope
  Home arrow Zope arrow Page 3 - The Number Game
Dev Shed Forums 
Administration  
AJAX  
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 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
SunQuest
 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

The Number Game
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 7
    2002-04-16

    Table of Contents:
  • The Number Game
  • Reading The Funnies
  • Start Me Up
  • Rocking The Vote
  • Down Memory Lane
  • Cookie-Cutter Code
  • Adding It All Up

  • 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

    Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!

    The Number Game - Start Me Up


    (Page 3 of 7 )

    With the database taken care of, it's time to get started with the user interface for our application. First things first - create a database connection as an instance of the Z MySQL Database Connection object and pass it the appropriate database name, user name and password. Remember that you can use the object's Test function to verify that the connection is working as it should.

    Now, the first DTML method needed is "viewCurrentPoll"; this invokes a Z SQL Method that connects to the database to retrieve the latest poll, and displays it with a list of possible responses. Take a look:

    <dtml-var standard_html_header> <dtml-in getCurrentPollDetails> <form action="addUserResponse"> <b><dtml-var question></b> <p> <input type="Radio" name="response" value="1"><dtml-var response1> <p> <input type="Radio" name="response" value="2"><dtml-var response2> <p> <input type="Radio" name="response" value="3"><dtml-var response3> <input type="hidden" name="qid" value="&dtml-qid;"> <p> <font size=-2><a href="viewPollResults?id=&dtml-qid;">view results</a></font> <font size=-2><a href="viewPollResults">view past polls</a></font> <p> <input type=submit name=submit value="Vote"> </form> </dtml-in> <dtml-var standard_html_footer>
    This DTML Method merely contains some plain-vanilla code to display a simple form to the user. The values in the form are fetched via the "getCurrentPollDetails" Z SQL Method. Here's what it looks like:

    SELECT qid, question, response1, response2, response3 from poll ORDER BY qid DESC
    Pay special attention to the SQL query that I've used here - I'm using the ORDER BY and DESC keywords to get all the records in descending order, so that the latest question appears first in the result set. Obviously, I also need to limit the result set to a single record - which can easily be done by hitting the advanced configuration for the Z SQL Method and setting the maximum number of rows to be retrieved to 1. In case you're wondering why I didn't just add a LIMIT clause to the SQL query above, there's a simple reason - Zope's MySQL database adapter doesn't support the use of LIMIT clauses in SQL statements (http://www.zope.org/Members/adustman/Tips/no_limits has more on this).

    The <dtml-in> construct is used to iterate through the results of the Z SQL Method invoked, and the form, once submitted, invokes the "addUserResponse" method to add the user's response to the database. Note that the identifier for the poll question is also included in the form, as a hidden field; when the form is submitted; this identifier will be used to ensure that the correct record is updated with the user's choice.

    Here's what it looks like:

    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

    SunQuest




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