[Zope-DB] Question involving passing optional parameters to a zsql method

Aaron Fosdick aaron at hypervision.com
Tue Oct 19 12:25:03 EDT 2004


This is very easy in my experience, just use dtml-sqlgroup.

If you're using mysql, make your checkbox fields enums. ex:
 golf enum('Y','N') default NULL,
 tennis enum('Y','N') default NULL,
 swim enum('Y','N') default NULL,

Your html looks like:
<INPUT TYPE="checkbox" NAME="golf" value="Y">Golf Course<BR>
<INPUT TYPE="checkbox" NAME="tennis" value="Y">Tennis Court<BR>
<INPUT TYPE="checkbox" NAME="swim" value="Y">Swimming Pool<BR>

And the method looks like:
Select somefields from db
<dtml-sqlgroup where>
...some match (required) ...
    <dtml-and>
        <dtml-sqltest golf type="nb" op=eq optional>
    <dtml-and>
        <dtml-sqltest tennis type="nb" op=eq optional>
    <dtml-and>
        <dtml-sqltest swim type="nb" op=eq optional>
</dtml-sqlgroup>

Make sure the initial query entry is always entered, otherwise you may 
get an error if the user doesn't select anything.

--Aaron


Laura McCord wrote:

>I have a form with 7 checkboxes. The more checkboxes are selected the
>more narrow of results you will get. I created a zsql method that will
>handle every case as far as when to include 'AND','OR', and '()'. 
>
>The problem now is getting my form to execute the zsql method correctly.
>When I hit the submit button the boxes that are not check will trigger
>an error message stating that the variable was not defined.
>
>I am trying to figure out when I hit the submit button my dtml method
>that runs the zsql method is not written to adjust for empty parameters.
>I had originally called my function like this:
> <dtml-call expr="findResults(location1=location1, location2=location2,
>..., usetype1=usetype1, usetype2=usetype2,...,active=active)">
>
>Does anyone have an idea on how to call this function regardless of what
>boxes are checked?
>
>thanks.
>_______________________________________________
>Zope-DB mailing list
>Zope-DB at zope.org
>http://mail.zope.org/mailman/listinfo/zope-db
>  
>



More information about the Zope-DB mailing list