Log in |
How to access the field names and fields of any arbitrary ZSQL queryIntroductionZSQL is a powerful method of accessing information from relational databases in a platform-independent manner. Sometimes, it is necessary to access the field names and the values of an SQL Query which cannot be told in advance. The names attributeField names of a ZSQL method can be accessed using the .names attribute AssumptionsYou already have a sql method called SQL Code: <dtml-in "SQL().names()"> <dtml-let vname=sequence-item vvalue="SQL()[0][_['sequence-index']]"> <dtml-var vname>, <dtml-var vvalue><br> </dtml-let> </dtml-in> or:: <dtml-with SQL> <dtml-in names> <dtml-let vname=sequence-item vvalue="SQL()[0][_['sequence-index']]"> <dtml-var vname>, <dtml-var vvalue><br> </dtml-let> </dtml-in> </dtml-with> CommentThe SQL()[0] returns the first row of a SQL query. In your code, you should check that rows exists before trying to access field values. |