I have a table containing attributes (attribute_id, attribute_name_string), and I have a table associating an object_id with 0 or more attributes (object_id, attribute_id). I want to populate a sequence of checkboxes in a dtml doc that has a checkbox for every attribute, but only the attributes assigned to the current object are checked. I cannot seem to generate sql that returns a table that contains all attribute_ids and attribute_name_strings, but only has object_ids on the rows for attributes assigned to that object, so I need to do it by querying for all attributes and then looping through the assigned attributes, looking for a match. However, I can't seem to do that, since having nested <dtml-in> tags creates a conflict, since both queries need to return an attribute_id field, and I need to compare the attribute_ids of both queries. That made no sense, so here is an example. qrySelectAllAtt returns a complete list of (att_id, att_string) qrySelectObjAtt returns a list of all (obj_id, att_id) where obj_id=x <dtml-in qrySelectAllAtt> <input name="blah" type="checkbox" value="blah" <dtml-in qrySelectObjAtt> THIS NEXT LINE DOESN'T WORK <dtml-if qrySelectObjAtt.att_id == qrySelectAllAtt.att_id> checked> <dtml-break> </dtml-if> > </dtml-in> </dtml-in> Of course, I would prefer some SQL that would generate the table I want in a single query. Perhaps someone who understands all the funky <dtml-sql> commands coould help me out. Alternatively, I wrote an external method that can do this loop, no problem. However, This is just a small piece of a huge form, and most of the form is based off yet another, simple query. I would like to build a dtml doc on that simple query that builds the bulk of the form, and then call that doc from inside the external method. I can call my dtml document from the external method, but it doesn't receive the REQUEST object (or the folder object), so the query fails to execute. I cannot figure out how to pass variables into the dtml doc (or method) from my external method. Is this possible? Without the self (folder) object, the dtml document can do nothing but spit out straight html. I still prefer the single query method, however, as it allows the query to only run once, instead of several times in a loop. --sam
At 11:40 pm -0800 4/11/99, Sam Gendler wrote:
qrySelectAllAtt returns a complete list of (att_id, att_string) qrySelectObjAtt returns a list of all (obj_id, att_id) where obj_id=x
<dtml-in qrySelectAllAtt> <input name="blah" type="checkbox" value="blah" <dtml-in qrySelectObjAtt> THIS NEXT LINE DOESN'T WORK <dtml-if qrySelectObjAtt.att_id == qrySelectAllAtt.att_id>
Try quoting the "if" statement, you've got an expression there...ie <dtml-if "qrySelectObjAtt.att_id == qrySelectAllAtt.att_id">
checked> <dtml-break> </dtml-if> > </dtml-in> </dtml-in>
tone ------ Dr Tony McDonald, FMCC, Networked Learning Environments Project http://nle.ncl.ac.uk/ The Medical School, Newcastle University Tel: +44 191 222 5888 Fingerprint: 3450 876D FA41 B926 D3DD F8C3 F2D0 C3B9 8B38 18A2
I still prefer the single query method, however, as it allows the query to only run once, instead of several times in a loop.
Try this (untested): SELECT object_id, attributes.attribute_id, attribute_name_string, object_id = <dtml-sqlvar object_id type=string> AS checked FROM objects , attributes WHERE attributes.attribute_id = objects.attribute_id; Use the 'checked' column to determine which items to check. One problem is that this will only select attributes which are assigned to some object, i.e. it will miss unassigned attributes. You could probably play around with making this an outer join and correct that problem. -jfarr ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Hi! I'm a signature virus. Copy me into your .sig to join the fun! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
participants (3)
-
Jonothan Farr -
Sam Gendler -
Tony McDonald