[Zope-DB] "Variable variables" (sort of)
Matthew Lindfield Seager
matthew at riskybusiness.com.au
Wed Sep 17 03:18:27 EDT 2003
Hi,
I've just read through a whole lot of python mailing lists regarding
php style "variable variables" because I thought that's what I
needed. But before I go too far down that path I thought I'd present
my problem here in case it's a simple one that I'm unnecessarily
overcomplicating (which wouldn't be a big surprise).
I have a database of records that I want users to be able to update
quickly i.e. they change 10 entries at a time and then hit submit
instead of having to modify a row, submit, modify, submit, modify,
submit, etc.
To acheive this I have created a form with a table in it. Each table
cell has an input and each input's "name" attribute is a combination
of the column name and row number. For the sake of argument let's say
my columns are id, name and gender, therefore the cells are id1,
name1 and gender1 (for row 1), id2, name2 and gender2 (for row 2) and
so on (assume that all the "id" inputs are hidden and therefore can't
be changed).
When the user hits submit I'd like to automatically have all 10 sql
queries executed with the different variables
UPDATE table
SET name=<dtml-sqlvar name1 type=string>, gender=<dtml-sqlvar
gender1 type=string>
WHERE <dtml-sqltest id1 column=id type=int>;
UPDATE table
SET name=<dtml-sqlvar name2 type=string>, gender=<dtml-sqlvar
gender2 type=string>
WHERE <dtml-sqltest id2 column=id type=int>;
etc...;
Is there a better way of doing this? Is there some way of passing 3
lists to the form processing dtml/python instead of having to pass 30
variables?
If there's not really a better way, how do I code it to automatically
iterate through all 10 rows to do the inserts? Well, more
importantly, how do I do it in such a way that it doesn't complain
when there are an unknown number rows (and therefore [three lots of
an unknown number of] variables). In php I could loop through with $i
and get the value of $id[$i] (which it would interpret as $id1, $id2,
etc). Is there something similar I can do in DTML or python?
Thanks in advance for any help!
Regards,
Matthew
P.S. I'm also passing back the number of rows that are coming so I
know there are going to be numRows * 3 cells/variables, if that helps.
More information about the Zope-DB
mailing list