For Programmers: Free Programming Magazines  


Home > Archive > ASP > March 2008 > Display recordset in columns









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Display recordset in columns
shank

2008-03-14, 6:59 pm

I would like to display a recordset using GetRows. The below works, but I
have to believe it's very crude. I googled for a solution and could only
find display that run horizontal. I want to display my results vertically. I
want to predetermine the use of 4 columns and divide the records evenly
across columns. Also, assuming 39 records, how would I get columns 1, 2, 3
to display 10 records and column 4 to display 9 records? Of course, the
number of records may change.

thanks

<%
' Retrieve the total # of rows
iRowNumber = ubound(arrResultSet,2)
%>
<%
varC1Begin = 0
varC1End = Round(iRowNumber/4)
varC2Begin = Round(varC1End) + 1
varC2End = Round(varC1End) * 2
varC3Begin = Round(varC2End) + 1
varC3End = Round(varC1End) * 3
varC4Begin = Round(varC3End) + 1
varC4End = Round(iRowNumber)
%>

<table width="0%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<%
' Loop through the array holding the result set and display the data
For iCounter= varC1Begin to varC1End
Response.Write(arrResultSet(0,iCounter) & "<br>")
Next
%><br>
</td>
<td>
<%
' Loop through the array holding the result set and display the data
For iCounter= varC2Begin to varC2End
Response.Write(arrResultSet(0,iCounter) & "<br>")
Next
%>
</td>
<td>
<%
' Loop through the array holding the result set and display the data
For iCounter= varC3Begin to varC3End
Response.Write(arrResultSet(0,iCounter) & "<br>")
Next
%>
</td>
<td>
<%
' Loop through the array holding the result set and display the data
For iCounter= varC4Begin to varC4End
Response.Write(arrResultSet(0,iCounter) & "<br>")
Next
%>
</td>
</tr>
</table>


Bob Barrows [MVP]

2008-03-14, 6:59 pm

shank wrote:
> I would like to display a recordset using GetRows. The below works,
> but I have to believe it's very crude.


In what way? Hard to maintain? Not giving you what you want? This
solution gives you 4 cells from what I can see. Is the problem that you
want it to give you 40 (10 rows of 4) cells, the last one of which is
empty?

> I googled for a solution and
> could only find display that run horizontal. I want to display my
> results vertically. I want to predetermine the use of 4 columns and
> divide the records evenly across columns. Also, assuming 39 records,
> how would I get columns 1, 2, 3 to display 10 records and column 4 to
> display 9 records? Of course, the number of records may change.
>

So you have a procedure that returns a bunch of records containing only
a single field, correct? And, given the records returned are numbered
1-39 you want them arranged like this?

1 11 21 31
....
9 19 29 39
10 20 30

It looks like your solution will do this - what's wrong with it?

This may be a small improvement, in that it allows you to specify the
number of cells you want:
<%
'open your recordset and use getrows to fill the array
if isarray(arrResultSet) then
response.write FillCells(arrResultSet,4)
else
response.write "No records returned"
end if

'***Functions used by the above statements ********************
Function FillCells(ByVal ar, ByVal cellcount)
Dim sHTML, i, j, cell1, cell2, cell3, cell4, curval, cellvals, vals
Dim arCells
If cellcount < 1 Then
FillCells = "Invalid Cellcount value - must be >= 1"
Else
ReDim arCells(cellcount - 1)
For i = 0 To cellcount - 1
arCells(i) = "<td>"
Next
vals = UBound(ar, 2) + 1
cellvals = CellValueCount(vals, cellcount)
For j = 1 To cellcount
For i = (j - 1) * cellvals To j * cellvals - 1
If vals > i Then
curval = ar(0, i)
arCells(j - 1) = WriteToCell(arCells(j - 1), curval)
End If
Next 'i
Next 'j
sHTML = "<table border=1><tr>"
For i = 0 To cellcount - 1
sHTML = sHTML & arCells(i) & "</td>"
Next
sHTML = sHTML & "</tr></table>"
FillCells = sHTML
End If
End Function
'***************************************
*****************************
Function CellValueCount(valcount, cellcount)
Dim tmp
tmp = valcount / cellcount
If CInt(tmp) = tmp Then
CellValueCount = tmp
ElseIf Int(tmp) < CInt(tmp) Then
CellValueCount = CInt(tmp)
Else
CellValueCount = CInt(tmp) + 1
End If
End Function
'***************************************
*****************************
Function WriteToCell(ByVal cell, ByVal val )
If cell = "<td>" Then
cell = cell & val
Else
cell = cell & "<br>" & val
End If
WriteToCell = cell
End Function
'***************************************
*****************************
%>
<html>
<head>
<style>
td {vertical-align:top}
</style>
<head>
<body>
</body>
</html>


I'm not sure how much of an improvement this is ...

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com