Click to See Complete Forum and Search --> : create an html table recursively using rowspans


marko_one
04-30-2003, 08:05 AM
Hi All,
I need to be able to build an html table (vb please). This table is composed of rowspans and

colspans which are not known intially until values are given from the database.

So for example, if I have data in a table which is for simplicity's sake CD collection.

This table can have columns:
Group Name (main item)
Group Members (children)
Tracks this year (grandchildren)

so if the group name is MyGroup, has 3 members, member 1 wrote 4 tracks, member 2 wrote 5

tracks and member 3 wrote 2 tracks.

The main item will have 3 children and 11 grandchildren. So the main item (Group Name) will

have a rowspan of 11, member 1 will have a rowspan of 4, member 2 will have a rowspan of 5 and

member 3 will have a rowspan of 2 in the HTML Table. The grandchildren will each be cells in

thier own right.

Obviously the rows in the database will not all be the same and so I need a way to be able to

create an HTML table for each row of the dataset.

so for my first row of the dataset, the table will be formed like this :


<table border="1" cellpadding="3" cellspacing="3">
<tr>
<td colSpan="" rowSpan="11">MyGroup</td>
<TD rowSpan="4">Member 1</TD>
<TD>member 1 track 1</TD>
</tr>
<TR>
<TD>member 1 track2</TD>
</TR>
<TR>
<TD>member 1 track 3</TD>
</TR>
<TR>
<TD>member 1 track 4</TD>
</TR>
<TR>
<TD rowSpan="5">Member 2</TD>
<TD>member 2 track 1</TD>
</TR>
<TR>
<TD>member 2 track 2</TD>
</TR>
<TR>
<TD>member 2 track 3</TD>
</TR>
<TR>
<TD>member 2 track 4</TD>
</TR>
<TR>
<TD>member 2 track 5</TD>
</TR>
<TR>
<TD rowSpan="2">Member 3</TD>
<TD>member 3 track 1</TD>
</TR>
<TR>
<TD>member 3 track 2</TD>
</TR>
</table>

can anybody help me out in developing a recursive function to create an html table given the numbers of children and grandchildren as these will be the rowspan values.

thanks in advance

Marko.

DaiWelsh
04-30-2003, 09:08 AM
If you use that exact format then I think you will need to do more than one run through the data as you need to decide in advance how many rows to span for group and member cells.

You might be better off using nested tables, then you can always just use single cells for group and member. I think you will find that the code is much simpler to write this way.

HTH,

Dai

marko_one
04-30-2003, 10:23 AM
thanks for the reply Dai,

I think maybe the example I gave was a bit poor, but the principle remains the same. The database will return Group, number of members, and number of tracks for each member. This will in fact give me the total number of grandchildren which will be the rowspan for the Group. The members will each have a value for the number of tracks they wrote, which will then be the rowspan for that cell. When this data has been collected from the database, we will have number of children from mygroup to members and number of children from members to tracks wrote which in total will give me the number of grandchildren. This can be the basis for the setting of rowspans of each column of the database.

I was only introduced to rowspans last week so my building of tables using rowspans is a bit weak at present.

If you have a method for me to format this from returned data then I'd love to see it - but I think the recursive approach is the answer, but i'm useless at recursion - which is why i'm asking.

thanks

Marko

Absinthe
05-09-2003, 03:16 PM
Why not do this:

make a table with two columns. In the first column place the Main item. In the second column, place another table then put in that tabel as many columns as necessary. Would this not achieve the effect you are after?

-- Absinthe

Originally posted by marko_one
Hi All,
I need to be able to build an html table (vb please). This table is composed of rowspans and

colspans which are not known intially until values are given from the database.

So for example, if I have data in a table which is for simplicity's sake CD collection.

This table can have columns:
Group Name (main item)
Group Members (children)
Tracks this year (grandchildren)

so if the group name is MyGroup, has 3 members, member 1 wrote 4 tracks, member 2 wrote 5

tracks and member 3 wrote 2 tracks.

The main item will have 3 children and 11 grandchildren. So the main item (Group Name) will

have a rowspan of 11, member 1 will have a rowspan of 4, member 2 will have a rowspan of 5 and

member 3 will have a rowspan of 2 in the HTML Table. The grandchildren will each be cells in

thier own right.

Obviously the rows in the database will not all be the same and so I need a way to be able to

create an HTML table for each row of the dataset.

so for my first row of the dataset, the table will be formed like this :


<table border="1" cellpadding="3" cellspacing="3">
<tr>
<td colSpan="" rowSpan="11">MyGroup</td>
<TD rowSpan="4">Member 1</TD>
<TD>member 1 track 1</TD>
</tr>
<TR>
<TD>member 1 track2</TD>
</TR>
<TR>
<TD>member 1 track 3</TD>
</TR>
<TR>
<TD>member 1 track 4</TD>
</TR>
<TR>
<TD rowSpan="5">Member 2</TD>
<TD>member 2 track 1</TD>
</TR>
<TR>
<TD>member 2 track 2</TD>
</TR>
<TR>
<TD>member 2 track 3</TD>
</TR>
<TR>
<TD>member 2 track 4</TD>
</TR>
<TR>
<TD>member 2 track 5</TD>
</TR>
<TR>
<TD rowSpan="2">Member 3</TD>
<TD>member 3 track 1</TD>
</TR>
<TR>
<TD>member 3 track 2</TD>
</TR>
</table>

can anybody help me out in developing a recursive function to create an html table given the numbers of children and grandchildren as these will be the rowspan values.

thanks in advance

Marko.

Ribeyed
05-09-2003, 03:54 PM
hi,
not sure if this will help you or not, but if i get what your trying to do then the following code should work. How don't you do the working for the number of rows you want to create then do a loop with a table inside the loop.


'do what working you need to get this value:
<%
numofgrandchildren = 11
for x = 1 to numofgrandchildren
%>
<table>
<tr>
<td>
data here!
</td>
</td>
data here!
<td>
</tr>
</table>
<%
next
%>