2009-10-11 53 views
2

我使用:web2py SQLTABLE - 如何轉置表?

rows = db(db.member.membership_id==request.args[0]).select(db.member.membership_id, 
    db.member.first_name, 
    db.member.middle_name, 
    db.member.last_name, 
    db.member.birthdate, 
    db.member.registration_date, 
    db.member.membership_end_date) 

rows.colnames = ('Membership Id', 'First Name', 'Middle Name', 'Last Name', 
    'Birthday Date', 'Registration Date', 'Membership ending Date') 
table = SQLTABLE(rows, _width="100%") 

現在我要轉表,我該怎麼辦呢?

+0

我注意到你在這裏找來找去的web2py的問題。我建議嘗試官方web2py論壇:http://groups.google.com/group/web2py – hoju

回答

1

試試這個:

rows=db(query).select(*fields).as_list() 
if rows: 
    table=TABLE(*[TR(TH(field),*[TD(row[field]) for row in rows]) \ 
     for field in row[0].keys()]) 
else: 
    table="nothing to see here" 
return dict(table=table) 
+0

此解決方案原因: UnboundLocalError:分配前引用的局部變量'row' – Neveen