Re: dtml-Variablen in <dtml-in> loops?
Hello again, Allright :-) I have cached the results of a sql-Method via <dtml-let DATA=sqlListProjects>. GroupID ProjectID Project 1 1 "Gurr" 1 2 "Muh" 2 3 "Ih-Ah" 3 4 "Mähh" 3 5 "WauWau" A second sqlMethod (sqlCount) returns: Count | 2 | ---- | 1 | ---- | 2 | ... The two sql-Methods are related: Count shoes, how many Projects belong to one GroupID. Now imagine that I want to print out the projects in the following way: GroupID 1: Gurr, Muh GroupID 2: Ih-Ah GroupID 3: Mäh, WauWau To do that I have an outer iteration over sqlCount's results: In this case it would iterate 3 times. Within each iteration there's another iteration - and this 2nd one depends on the current row's Count (2 times in the 1st outer iteration, 1 time in the 2nd iteration etc.). To print out the projects within the inner iteration I use the following technique: <dtml-in "sqlCount(_.None,_)"> //outer iteration! <dtml-if sequence-start> <dtml-call "REQUEST.set('TEMP',1)"> </dtml-if sequence-start> <dtml-call "REQUEST.set('TEMP2', (TEMP+_.getitem('Count'))-1)"> <dtml-in DATA start=TEMP end=TEMP2> //inner iteration //Print ProjectIDs here </dtml-in> <dtml-call "REQUEST.set('TEMP', TEMP+(_.getitem('Count')))"> </dtml-in> It may take some time to understand the code but it actually works as it should. I simply would prefer a cleaner solution where I would avoid the creation of different variables via REQUEST.set (which are then used in <dtml-in DATA start=VARIABLE) but simply do the calculation within the "start=" and "end=" Was that still a bad description of my problem? Thanks again, Philipp Robbel
Hi Philipp, --On Sonntag, 27. Mai 2001 16:08 +0200 Philipp Robbel <philipp.robbel@eml.villa-bosch.de> wrote:
Hello again,
Allright :-) I have cached the results of a sql-Method via <dtml-let DATA=sqlListProjects>. GroupID ProjectID Project 1 1 "Gurr" 1 2 "Muh" 2 3 "Ih-Ah" 3 4 "Mähh" 3 5 "WauWau"
A second sqlMethod (sqlCount) returns: Count | 2 | ---- | 1 | ---- | 2 | ...
The two sql-Methods are related: Count shoes, how many Projects belong to one GroupID. Now imagine that I want to print out the projects in the following way:
GroupID 1: Gurr, Muh
GroupID 2: Ih-Ah
GroupID 3: Mäh, WauWau
First of all, you dont have to cache SQL results via dtml-let. Zope does this already for you. If you have 2 queries: sqlGroupList: SELECT DISTINCT GroupID FROM Projects and the other: sqlProjectList(arg_GroupID) SELECT ProjectID, Project FROM Projects WHERE GroupID=<dtml-arg_GroupID type=int> so you can: <dtml-in sqlGroupList> GroupID &dtml-GroupID;: <dtml-in "sqlProjectList(arg_GroupID=GroupID)"> <dtml-unless sequence-start>,</dtml-unless> <dtml-var Project> </dtml-in> </dtml-in> This looks a bit cleaner imho ;) Regards Tino Wildenhain
participants (2)
-
Philipp Robbel -
Tino Wildenhain