[Zope] Using lists in DTML
Ken Kinder
kkinder@messagemedia.com
Wed, 05 Apr 2000 14:36:03 -0600
I'm using Oracle flavor SQL. Can I use that SQL on more than two? This
will eventually be three queries.
"Christopher J. Kucera" wrote:
>
> Ken Kinder wrote:
> > lists. How would I eliminate duplicates created by querying the
> > same table?
> >
> > Any ideas on what syntax I would use for that?
>
> What kind of SQL statements are your running?
>
> If you have the SQL queries returning the same data types, and you're
> using a database that supports it, you could actually combine the SQL
> statements into one with a UNION:
>
> select first, second from sometable where second='blahblah'
> union select first, second from sometable where third='foo'
>
> (Although, that statement could easily be reduced to
> "... where second='blahblah' or third='foo'") Depending on the flavor of
> SQL, you might have to add another keyword in there somehwere to remove
> duplicates.
>
> If you'd still like to build a list of keys though, you could do the
> following (untested):
>
> <dtml-let mylist="[]">
> <ul>
> <dtml-in ..>
> <dtml-call "mylist.append(fieldname)">
> <li>..
> </dtml-in>
> <dtml-in ..>
> <dtml-try>
> <dtml-if "mylist.index(fieldname) > -1">
> <li>..
> </dtml-if>
> <dtml-except>
> Already had this item . . .
> </dtml-try>
> </dtml-in>
> </ul>
> </dtml-let>
>
> The dtml-try in there is because the "index" function on a list gives an
> error if the item is not found. I don't know of any function that'll just
> return -1 or something, but I'm sure you could write one in python.
>
> Hope that helps some,
> -CJ
>
> _______________________________________________
> 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 )
--
Ken Kinder
303.381.7631