Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help creating html table from Database

Status
Not open for further replies.

morechocolate

Technical User
Apr 5, 2001
225
US
This is a two part question.

I am populating a HTML table from recordsets returned from a table in my database. I am not sure how to do what I want.

1. I want a table structure like so (all the info comes from the database) Do I need to use a for loop in addition to the usual Do Until NOT rs.EOF?

a b d e
f g h i

2. How to I handle the table structure if there is not an even number of items being retured from the table? I am worried about the colspan issue.

a b d e
f g

Thank You
 
Hi,
I had the same problem that you are having in a ASP page I've made.
I solved it with something like this:

I'm going to show you only the logic code structure:
<table>
<tr>
<td align=&quot;left&quot;>
<table>
<%
'&quot;control_col&quot; controls how many columns your table will
'have
control_col = 0

'here you will open connection, and make the select
'statement

Do while not rs.eof
control_col = control_col + 1
%>
<tr>
<td>
<%
'here you will put all the info that will be shown
%>
</td>
</tr>
<%
'this next &quot;IF&quot; will end the table when you reach (in
'this case) the fourth column, just change the value if
'you want to :)

If control_col = 4 then
response.write &quot;</table><table>&quot;
else
end if

rs.movenext
loop

If control_col <> 4 then
%>
</table>
<%
else
end if
%>
</td>
</tr>
</table>

that's it..... this solved my problems.... you don't have to worry about colspan..... :)) well, I hope this helps

Frederico
 
Thanks Fredrico. I will give it a try and let you know how it worked out.

Pam
 
Frederico - First sorry for spelling your name wrong before.

Good news...you code sample worked like a charm. Thanks a bunch.
 
I forgot to say one more thing... :)
here where you close the table tags, if in the future you want to put more information and still want to keep breaking up the lines, you'll have to set control_col=0, because then every 4 columns it will break up the line.

If control_col = 4 then
response.write &quot;</table><table>&quot;
control_col = 0
else
end if
Glad to help,

Frederico
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top