How to build a table layout

C

CD

I would like some guidance as to how to proceed to build a webpage in asp or
aspx. I am going to hit a SQL db needing to get the following data:

SELECT ServerName,PrimaryTech FROM tblservers GROUP BY
PrimaryTech,ServerName

The idea is to display the data in a table format where the Column header
would the PrimaryTech and under each tech would the ServerName they are
responsible for.

ie.....
John Matt Joe
Srv1 Srv3 Srv2
Srv4 Srv6 Srv14

TIA
CD
 
R

Ray Costanzo [MVP]

You'll wind up with data like:

John Srv1
Joe Srv14
Joe Srv2
Matt Srv3
John Srv4
Matt Srv6


Throw in an order by clause, ORDER BY PrimaryTech,ServerName so you have
data like:

Joe Srv14
Joe Srv2
John Srv1
John Srv4
Matt Srv3
Matt Srv6

Unfortunately, when you write out tables in HTML, your only option is to go
left to right, and top to bottom. You can't do columns at a time. So, then
the question becomes an HTML design issue. If you want to keep this all in
one query, as opposed to executing a query for each person, you could do
something like:



<table border="1">
<tr>
<%

Dim sOldname, sCurrentname
sOldname = ""

Do while not yourRecordset.EOF
sCurrentname = yourRecordset.Fields.Item("PrimaryTech").Value
If sCurrentname <> sOldname Then Response.Write "<td>"
Response.Write yourRecordset.Fields.Item("ServerName").Value & "<br>"
sCurrentname = yourRecordset.Fields.Item("PrimaryTech").Value
If sCurrentname <> sOldname Then
Response.Write "<td>"
Response.Write sCurrentname & "<br>"
End If
Response.Write yourRecordset.Fields.Item("ServerName").Value & "<br>" &
vbCrLf

yourRecordset.MoveNext
sOldname = sCurrentname
sCurrentname = yourRecordset.Fields.Item("PrimaryTech").Value
If sCurrentname <> sOldname Then Response.WRite "</td>"
Loop
%>
</tr>
</table>



Ray at work
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top