get recordset value outside the table

H

Hamster

I need to display data like this:

CompanyName1

Company | Date| Transactions Count -- headers
CompanyName1 | Date| 1 -- data
CompanyName2 | Date| 5 -- data
CompanyName3 | Date| 2 -- data
CompanyName4 | Date| 7 -- data



COMPANYNAME1 should be outside the table
<table>
<tr>
<%
For each fld in objRS.Fields
Response.Write("<td>" & fld.Name & "</td>")
Next
objRS.MoveFirst
%>
</tr>
<%
Do until objRS.EOF
%>
<tr>
<%
For each fld in objRS.Fields
Response.Write("<td>" & fld & "</td>")
Next
objRS.MoveNext
%>
</tr>
</table>

Help please!
 
B

Bob Barrows

Hamster said:
I need to display data like this:

CompanyName1

Company | Date| Transactions Count -- headers
CompanyName1 | Date| 1 -- data
CompanyName2 | Date| 5 -- data
CompanyName3 | Date| 2 -- data
CompanyName4 | Date| 7 -- data



COMPANYNAME1 should be outside the table
<table>
<tr>
<%
For each fld in objRS.Fields
Response.Write("<td>" & fld.Name & "</td>")
Next
objRS.MoveFirst
%>
</tr>
<%
Do until objRS.EOF
%>
<tr>
<%
For each fld in objRS.Fields
Response.Write("<td>" & fld & "</td>")
Next
objRS.MoveNext
%>
</tr>
</table>

Help please!

Please rephrase your question.

Bob Barrows
 
K

Katya Kotova

I have table with headers and data populated dynamically.

<table border="1" cellpadding="0" cellspacing="0">
<tr>
<%
For each fld in objRS.Fields
Response.Write("<td>" & fld.Name & "</td>")
Next
objRS.MoveFirst
%>
</tr>
<%
Do until objRS.EOF
%>
<tr>
<%
For each fld in objRS.Fields
Response.Write("<td>" & fld & "</td>")
Next
objRS.MoveNext
%>
</tr>
<%
Loop
%>
</table>

What I need:
1)C1 to be the title of the table, it should be outside <table> tag
2)Company column to be hidden (I know the column to be hidden, it's the
one that has ~T~ at the end)

C1

Company | Date | Transaction
C1 12/12/2003 Transaction1
C1 12/13/2003 Transaction2
C1 12/14/2003 Transaction3

Thanks.
 
B

Bob Barrows

Katya said:
What I need:
1)C1 to be the title of the table, it should be outside <table> tag

That's easy enough. It looks like every record in the recordset has "C1" in
the first field. So just read the value of the first field and write it to
the response before starting the table.

2)Company column to be hidden (I know the column to be hidden, it's
the one that has ~T~ at the end)

Sorry, but this means nothing to me. I'm not looking over your shoulder. I
don't know where you are seeing this "~T~".

I'm assuming Company is the first field in the recordset? Why create the
column in the table if you want it to be hidden?


<%
'open the recordset - use rs, not objRS (less typing)
Response.write rs(0)
%>
<table border="1" cellpadding="0" cellspacing="0">
<%
Dim i
response.write "<tr>"
for i = 1 to rs.Fields.count - 1
Response.Write("<td>" & rs.Fields(i).Name & "</td>")
next
response.write "</tr>"
'no need to do a MoveFirst here
Do until rs.EOF
response.write "<tr>"
for i = 1 to rs.Fields.count - 1
Response.Write("<td>" & rs(i) & "</td>")
next
response.write "</tr>"
loop
response.write "</table>"
%>

HTH,
Bob Barrows
 
K

Katya Kotova

Thanks.
I would like to do this for every column that has, for example,
Right(fld.Name, 4) = "name", not only for the first column.

I am creating a universal component that I can use for a lot of web
reports.
 
B

Bob Barrows

Katya said:
Thanks.
I would like to do this for every column that has, for example,
Right(fld.Name, 4) = "name", not only for the first column.

I am creating a universal component that I can use for a lot of web
reports.
Please provide a more detailed example that thoroughly explains what you
mean by "do this".

Bob Barrows
 
K

Katya Kotova

I would like to take first field value from column that has "name" at
the end (it can be 2nd, 3rd, 11th column)and to make this value to be a
title of this table.

Smith & Co

ID | EmployeeID | Contact | CompanyName |
12 | 12345 | Smith | Smith & Co
13 | 12346 | Gardner | Smith & Co

Thanks for your patience.


I am trying to create component that I can use for a number of web
reports. It should determine the column name with "name" at the end, and
if it exists it should create a title from it's first value and hide
this particular column.
 
B

Bob Barrows

Katya said:
I would like to take first field value from column that has "name" at
the end (it can be 2nd, 3rd, 11th column)and to make this value to be
a title of this table.

Smith & Co

ID | EmployeeID | Contact | CompanyName |
12 | 12345 | Smith | Smith & Co
13 | 12346 | Gardner | Smith & Co

Thanks for your patience.


I am trying to create component that I can use for a number of web
reports. It should determine the column name with "name" at the end,
and if it exists it should create a title from it's first value and
hide this particular column.
 
B

Bob Barrows

Katya said:
I would like to take first field value from column that has "name" at
the end (it can be 2nd, 3rd, 11th column)and to make this value to be
a title of this table.

Smith & Co

ID | EmployeeID | Contact | CompanyName |
12 | 12345 | Smith | Smith & Co
13 | 12346 | Gardner | Smith & Co

Thanks for your patience.


I am trying to create component that I can use for a number of web
reports. It should determine the column name with "name" at the end,
and if it exists it should create a title from it's first value and
hide this particular column.

Errm, OK.

I assume you will have some method to make sure that only one field ends
with the word "name" given that you don't know either the names of the
fields or the order in which they will be retrieved ...?

Enough with this inefficient recordset looping. Time to use some arrays:

'open the recordset, then
Dim arData. arNames(), i, j, NameIndex
redim arNames(rs.Fields.Count - 1)
for i = 0 to rs.Fields.Count - 1
if lcase(Right(rs.Fields(i).Name,4)) = "name" then NameIndex = i
arNames(i) = rs.Fields(i).Name
next
if not rs.EOF then arData = rs.GetRows
rs.close: set rs=nothing
'close and destroy the connection as well

'arData will not be an array if no records were returned
If IsArray(arData) then

'write the value contained in the column identified by NameIndex
'from the first row of data in arData
Response.Write arData(NameIndex,0) & "<BR>"

'Build the table using all columns except the one identified by
'NameIndex

Response.Write "<table><tr>"
for i = 0 to ubound(arNames)
if i <> NameIndex then
Response.Write "<th>"
Response.Write arNames(i)
Response.Write "</th>"
End If
next
Response.Write "</tr>"

for i = 0 to Ubound(arData,2)
Response.Write "<tr>"
for j = 0 to Ubound(arData,1)
If j <> NameIndex then
Response.Write "<td>"
Response.Write arData(j,i)
Response.Write "</td>"
End if
next
Response.Write "</tr>"
next
Response.Write "</table>"

Else
'handle the situation where no records were returned
End if

HTH,
Bob Barrows
 

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

Forum statistics

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

Latest Threads

Top