Question: How do I transpose the contents of a 2-D array? Purpose: I have a ZSQL-Method which returns the rows (Model 1, Model 2 etc) as in Diagram 1 below (best viewed in a fixed-width font). I want to present this information in an HTML table as in Diagram 2 below. Diagram 1 ========= Model | Feature 1 | Feature 2 | Feature 3 | Feature 4 --------+-----------+-----------+-----------+----------- Model 1 | Yes | Yes | Yes | No --------+-----------+-----------+-----------+----------- Model 2 | Yes | Yes | No | No --------+-----------+-----------+-----------+----------- Model 3 | No | Yes | No | Yes Diagram 2 ========= | Model 1 | Model 2 | Model 3 ----------+---------+---------+--------- Feature 1 | Yes | Yes | No ----------+---------+---------+--------- Feature 2 | Yes | Yes | Yes ----------+---------+---------+--------- Feature 3 | Yes | No | No ----------+---------+---------+--------- Feature 4 | No | No | Yes tia - Jason Wong Digital View Ltd 2201 Nanyang Plaza 57 Hung To Road Kwun Tong HONG KONG Tel: +852-2861-3615 Fax: +852-2520-2987 www.digitalview.com
Jason Wong wrote:
Question: How do I transpose the contents of a 2-D array?
<dtml-var standard_html_header> <dtml-call "REQUEST.set('m',[[1,2,3],[4,5,6],[7,8,9],[10,11,12]])"> <table border=1> <tr><th colspan="<dtml-var "_.len(m[0])+1">">STRAIGHT</th></tr> <dtml-in m> <dtml-call "REQUEST.set('row',_['sequence-index'])"> <tr> <dtml-in sequence-item> <dtml-call "REQUEST.set('col',_['sequence-index'])"> <td>[<dtml-var row>:<dtml-var col>] <dtml-var "m[row][col]"></td> </dtml-in> </tr> </dtml-in> </table> <table border=1> <tr><th colspan="<dtml-var "_.len(m)+1">">TRANSPOSED</th></tr> <dtml-in "m[0]"> <dtml-call "REQUEST.set('col',_['sequence-index'])"> <tr> <dtml-in m> <dtml-call "REQUEST.set('row',_['sequence-index'])"> <td>[<dtml-var row>:<dtml-var col>] <dtml-var "m[row][col]"></td> </dtml-in> </tr> </dtml-in> </table> </p> <dtml-var standard_html_footer> ---------------- Hannu
participants (2)
-
Hannu Krosing -
Jason Wong