Building tables from a db in dtml...
So, I want to generate a table using DTML and data from a database. I want each row returned from the database to go into it's own html cell, and I want to have say, 4 html columns across the page before starting a new row. So like: <table> <tr> <td> Row 1 from DB </td> <td> row 2 from db </td> <td> row 3 from db </td> <td> row 4 from db </td> </tr> <tr> <td> row 5 from db </td> ... How can I do this? Is there some kind of dtml-if I can wrap around the </tr><tr> to only make it show every 4th row? -- Miksch's Law: If a string has one end, then it has another end.
From: <jiva@devware.com>
So, I want to generate a table using DTML and data from a database. I want each row returned from the database to go into it's own html cell, and I want to have say, 4 html columns across the page before starting a new row. So like:
<table> <tr> <td> Row 1 from DB </td> <td> row 2 from db </td> <td> row 3 from db </td> <td> row 4 from db </td> </tr> <tr> <td> row 5 from db </td> ...
How can I do this? Is there some kind of dtml-if I can wrap around the </tr><tr> to only make it show every 4th row?
You could use the count- variable to find the rows where you need to insert the <tr>'s. If the returned column name is 'value', use code like this (untested): <table><tr> <dtml-in db_query> <dtml-if "_['count-value'] % 4 == 0"></tr><tr></dtml-if> <td><dtml-var value></td> </dtml-in> </tr></table> Now, I could be wrong and count-value is 1 based in stead of 0 based. In fact, I believe it is, it would make sense anyway. Then you'd adjust the logic slightly, something like (_['count-value'] - 1) % 4. -- Martijn Pieters | Software Engineer mailto:mj@digicool.com | Digital Creations http://www.digicool.com/ | Creators of Zope http://www.zope.org/ | The Open Source Web Application Server ---------------------------------------------
Try this (untested): <dtml-in query> <dtml-if "_['sequence-start']"> <table><tr> </dtml-if> <dtml-if "_.int(_['sequence-index'])!=0 and (_.int(_['sequence-index'])+1)%4==1"> </tr><tr> </dtml-if> <td>Row1</td> .... </dtml-in> </tr></table> __________________________________________________________________ Jim Sanford . Database/Web Engineer / \ / Accelerated Technology, Inc. / / 720 Oak Circle Drive East / / \ Mobile, AL 36609 / / \ Voice: 334-661-5770 fax: 334-661-5788 / \ E-Mail: jsanford@atinucleus.com Web: http://www.atinucleus.com Source Code, No Royalties, Any CPU...It just make sense ! __________________________________________________________________ ----- Original Message ----- From: <jiva@devware.com> To: <zope@zope.org> Sent: Saturday, February 26, 2000 10:44 PM Subject: [Zope] Building tables from a db in dtml... So, I want to generate a table using DTML and data from a database. I want each row returned from the database to go into it's own html cell, and I want to have say, 4 html columns across the page before starting a new row. So like: <table> <tr> <td> Row 1 from DB </td> <td> row 2 from db </td> <td> row 3 from db </td> <td> row 4 from db </td> </tr> <tr> <td> row 5 from db </td> ... How can I do this? Is there some kind of dtml-if I can wrap around the </tr><tr> to only make it show every 4th row? -- Miksch's Law: If a string has one end, then it has another end. _______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (3)
-
Jim Sanford -
jiva@devware.com -
Martijn Pieters