[Zope] Passing variables from ZSQL Methods

Norman Khine norman@khine.net
Sun, 13 Oct 2002 18:48:15 +0100


Hello,
Can someone please point me in the right direction, I have the following
python script:

print '<SCRIPT LANGUAGE="JavaScript">'
print '<!-- Begin'
print """if (!assocArray) var assocArray = new Object();"""
regions = context.sql_list_region()
for region in regions:
  print """assocArray["region_list="%d"] =  new Array("('Select
county','',true,true)",""" % region.region_id
  counties= context.sql_list_county()
  for county in counties:
    print '''"('%d')",''' % county.county_id

  print " ); "

print "-->"
print "</script>"

return printed

this connects to two z sql methods, sql_list_region and sql_list_county
respectively and the result i get is:

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
if (!assocArray) var assocArray = new Object();
assocArray["region_list="2"] =  new Array("('Select county','',true,true)",
"('1')",
"('2')",
"('3')",
"('4')",
"('5')",
...........
..........
"('80')",
 );
assocArray["region_list="3"] =  new Array("('Select county','',true,true)",
"('1')",
"('2')",
"('3')",
"('4')",
"('5')",

and so on..........

"('79')",
"('80')",
 );
-->
</script>

Now one of the problems I am having is that I want to be able to for each
region_id to be able to list the related counties, so i passed a variable in
the sql_list_county ZSQL Method, which is as follows:

arguments: region_id:int=0
select county, county_id from county where region_id=region_id

but this returns the whole list for the counties, where as i want to be able
to itarate for each region_id.

also in the above script, how do i return both the county_id and county
within the same print statement?

thanks in advance

norman