Thanks Massimo,
I tried the code you suggest and received the following error:
table.append(TR(*[TH(field) for field in db[table].fields]))
KeyError: <gluon.html.TABLE object at 0x923cf8c>
Any idea why?
Ed
On Oct 1, 8:13 pm, mdipierro <[EMAIL PROTECTED]> wrote:
> You can but your implementation is not the way to do it. If you have
> html in strings you are doing it wrong.
> Here is how you do it in a view:
>
> {{for table in db.tables:}}
> <h2>{{=table}}</h2>
> {{=db().select(db[table].ALL)}}
> {{pass}}
>
> or more exlicitly:
>
> {{for table in db.tables:}}
> <h2>{{=table}}</h2>
> <table>
> <tr>{{for field in db[table].fields:}}<th>{{=field}}</th></tr>
> {{for row in db().select(db[table].ALL):}}
> <tr>{{for field in db[table].fields:}}<th>{{=row[field]}}</th></tr>
> {{pass}}
> </table>
> {{pass}}
>
> this is how you do the same in a controller
>
> div=DIV()
> for table in db.tables:
> div.append(H2(table))
> table=TABLE()
> table.append(TR(*[TH(field) for field in db[table].fields]))
> for row in db().select(db[table].ALL):
> table.append(TR(*[TD(row[field] for field in
> db[table].fields]))
> div.append(table)
> return div
>
> On Oct 1, 6:57 pm, JorgeRpo <[EMAIL PROTECTED]> wrote:
>
> > why dont you use the template syntax?
>
> > Ed wrote:
> > > Hi,
>
> > > I want to be able to access, using theORMbut not executesql(), all
> > > the data within my database without knowing the names of the tables or
> > > fields. Essentially, I want code that looks something like this
>
> > > for table in MyDb.tables:
> > > html += "<h2>" + str(table) + "</h2>" # works!
>
> > > html += "<table>"
>
> > > html += "<tr>"
> > > for field in table.fields: # doesn't work
> > > html += "<th>" + str(field.name) + ":" +
> > > "str(field.value)" + "</th>"
> > > html += "</tr>"
>
> > > for row in table.rows: # doesn't work
> > > html += "<tr>"
>
> > > for cell in row.cells:
> > > html += "<td>" + str(cell.field.name) + ":" +
> > > "str(cell.field.value)" + "</td>"
>
> > > html += "</tr>"
>
> > > html += "</table>"
>
> > > Is that possible (and legal) in Web2py?
>
> > > Thanks,
> > > Ed
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---