Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > The best method to list by columns from a db

Reply
Thread Tools

The best method to list by columns from a db

 
 
PiGei
Guest
Posts: n/a
 
      04-18-2005
hi all,
I'm using the following code to read articles from a db and show them by
columns and not by rows.
I think the code could be better... so, if you have some advice...

thanks

db= access

<%
Dim num_col 'number of columns
Dim end_row 'checking enf of row
Dim counter

num_col = 2
end_row = "false"
counter = 1
%>

<table border="1" cellpadding="2" cellspacing="2" width="450">
<%
Do While Not rstSimple.EOF
%>
<%
If end_row = "false" Then
response.write "<tr>"
End If
%>
<td>
<%= rstSimple.Fields("id").Value %><br>
<%= rstSimple.Fields("titolo").Value %><br>
<%= rstSimple.Fields("data").Value %><br>
<%= "end_row= " & end_row %><br>
<%= "counter= " & counter %><br>
<%= "num_col= " & num_col %><br>
</td>
<%
rstSimple.MoveNext
%>
<%
If counter = num_col OR rstSimple.EOF Then
response.write "</tr>"
end_row = "false"
counter = 1
%>
<%
Else
%>
<% counter = counter+1 %>
<% end_row = "true" %>
<% End If %>
<%
Loop
%>
</table>

Thanks


 
Reply With Quote
 
 
 
 
Dave Anderson
Guest
Posts: n/a
 
      04-18-2005
PiGei wrote:
> hi all,
> I'm using the following code to read articles from a db and show them
> by columns and not by rows.
> I think the code could be better... so, if you have some advice...


You might want to consider using GetRows():
http://msdn.microsoft.com/library/en...mthgetrows.asp


This is why (thanks to ASP FAQ):

"By its very nature, the 2-dimensional array returned by the GetRows
method is non-linear. This has important implications for the ways
in which the result set data can be processed. The data in the result
set can be processed in a row-by-row, column-by-column or cell-by-cell
manner, or any combination there-of. Formatting can also take place at
the row, column and/or cell level."

http://aspfaq.com/show.asp?id=2467



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.


 
Reply With Quote
 
 
 
 
PiGei
Guest
Posts: n/a
 
      04-18-2005
Thanks
PGei

"Dave Anderson" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> PiGei wrote:
>> hi all,
>> I'm using the following code to read articles from a db and show them
>> by columns and not by rows.
>> I think the code could be better... so, if you have some advice...

>
> You might want to consider using GetRows():
> http://msdn.microsoft.com/library/en...mthgetrows.asp
>
>
> This is why (thanks to ASP FAQ):
>
> "By its very nature, the 2-dimensional array returned by the GetRows
> method is non-linear. This has important implications for the ways
> in which the result set data can be processed. The data in the result
> set can be processed in a row-by-row, column-by-column or cell-by-cell
> manner, or any combination there-of. Formatting can also take place at
> the row, column and/or cell level."
>
> http://aspfaq.com/show.asp?id=2467
>
>
>
> --
> Dave Anderson
>
> Unsolicited commercial email will be read at a cost of $500 per message.
> Use of this email address implies consent to these terms. Please do not
> contact me directly or ask me to contact you directly for assistance. If
> your question is worth asking, it's worth posting.
>



 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      04-18-2005
PiGei wrote:
> hi all,
> I'm using the following code to read articles from a db and show them
> by columns and not by rows.
> I think the code could be better... so, if you have some advice...
>
> thanks
>
> db= access
>
> <%
> Dim num_col 'number of columns
> Dim end_row 'checking enf of row
> Dim counter
>
> num_col = 2
> end_row = "false"
> counter = 1
> %>
>
> <table border="1" cellpadding="2" cellspacing="2" width="450">
> <%
> Do While Not rstSimple.EOF
> %>
> <%
> If end_row = "false" Then
> response.write "<tr>"
> End If
> %>
> <td>
> <%= rstSimple.Fields("id").Value %><br>
> <%= rstSimple.Fields("titolo").Value %><br>
> <%= rstSimple.Fields("data").Value %><br>
> <%= "end_row= " & end_row %><br>
> <%= "counter= " & counter %><br>
> <%= "num_col= " & num_col %><br>
> </td>
> <%
> rstSimple.MoveNext
> %>
> <%
> If counter = num_col OR rstSimple.EOF Then
> response.write "</tr>"
> end_row = "false"
> counter = 1
> %>
> <%
> Else
> %>
> <% counter = counter+1 %>
> <% end_row = "true" %>
> <% End If %>
> <%
> Loop
> %>
> </table>
>
> Thanks


This should be better:
<%
Dim num_col 'number of columns
dim iRows, iRow
Dim iCol
dim arData, i, j
dim arHTML(), sHTML, sCell

num_col = 2
arData = rstSimple.GetRows

rstSimple.close:set rstSimple=nothing
'close and destroy your connection here as well

if isArray(arData) then
sHTML = "<TABLE border=""1"" cellpadding=""2""" & _
" cellspacing=""2"" width=""450"">"
iRows = ubound(arData,2) \ num_col
if ubound(arData,2) mod num_col > 0 then iRows = iRows+1
reDim arHTML(iRows)
for i = 0 to ubound(arData,2)
iCol= (i mod num_col) + 1
iRow=(i \ num_col) + 1
if iCol = 1 then
sCell = "<TR><TD>"
elseif sCol < num_col then
sCell=sCell & "<TD>"
end if
sCell=sCell & arData(0,i)
for j=1 to 2
sCell = sCell & "<BR>" & arData(j,i)
next
sCell = sCell & "<BR>Column= " & iCol
sCell = sCell & "<BR>Row= " & iRow & "</TD>"
if iCol = num_col then
arHTML(iRow - 1) = sCell & "</TR>"
elseif i = ubound(arData,2) then
do until iCol = num_col
sCell = sCell & "<TD> &nbsp;</TD>"
iCol=iCol+1
loop
arHTML(iRow - 1) = sCell & "</TR>"
end if
next
sHTML = sHTML & join(arHTML,vbCrLf) & "</TABLE>"
else
sHTML = "No data was returned"
end if
Response.Write sHTML
%>

HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
PiGei
Guest
Posts: n/a
 
      04-18-2005
Thanks Bob
PGei

"Bob Barrows [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> PiGei wrote:
>> hi all,
>> I'm using the following code to read articles from a db and show them
>> by columns and not by rows.
>> I think the code could be better... so, if you have some advice...
>>
>> thanks
>>
>> db= access
>>
>> <%
>> Dim num_col 'number of columns
>> Dim end_row 'checking enf of row
>> Dim counter
>>
>> num_col = 2
>> end_row = "false"
>> counter = 1
>> %>
>>
>> <table border="1" cellpadding="2" cellspacing="2" width="450">
>> <%
>> Do While Not rstSimple.EOF
>> %>
>> <%
>> If end_row = "false" Then
>> response.write "<tr>"
>> End If
>> %>
>> <td>
>> <%= rstSimple.Fields("id").Value %><br>
>> <%= rstSimple.Fields("titolo").Value %><br>
>> <%= rstSimple.Fields("data").Value %><br>
>> <%= "end_row= " & end_row %><br>
>> <%= "counter= " & counter %><br>
>> <%= "num_col= " & num_col %><br>
>> </td>
>> <%
>> rstSimple.MoveNext
>> %>
>> <%
>> If counter = num_col OR rstSimple.EOF Then
>> response.write "</tr>"
>> end_row = "false"
>> counter = 1
>> %>
>> <%
>> Else
>> %>
>> <% counter = counter+1 %>
>> <% end_row = "true" %>
>> <% End If %>
>> <%
>> Loop
>> %>
>> </table>
>>
>> Thanks

>
> This should be better:
> <%
> Dim num_col 'number of columns
> dim iRows, iRow
> Dim iCol
> dim arData, i, j
> dim arHTML(), sHTML, sCell
>
> num_col = 2
> arData = rstSimple.GetRows
>
> rstSimple.close:set rstSimple=nothing
> 'close and destroy your connection here as well
>
> if isArray(arData) then
> sHTML = "<TABLE border=""1"" cellpadding=""2""" & _
> " cellspacing=""2"" width=""450"">"
> iRows = ubound(arData,2) \ num_col
> if ubound(arData,2) mod num_col > 0 then iRows = iRows+1
> reDim arHTML(iRows)
> for i = 0 to ubound(arData,2)
> iCol= (i mod num_col) + 1
> iRow=(i \ num_col) + 1
> if iCol = 1 then
> sCell = "<TR><TD>"
> elseif sCol < num_col then
> sCell=sCell & "<TD>"
> end if
> sCell=sCell & arData(0,i)
> for j=1 to 2
> sCell = sCell & "<BR>" & arData(j,i)
> next
> sCell = sCell & "<BR>Column= " & iCol
> sCell = sCell & "<BR>Row= " & iRow & "</TD>"
> if iCol = num_col then
> arHTML(iRow - 1) = sCell & "</TR>"
> elseif i = ubound(arData,2) then
> do until iCol = num_col
> sCell = sCell & "<TD> &nbsp;</TD>"
> iCol=iCol+1
> loop
> arHTML(iRow - 1) = sCell & "</TR>"
> end if
> next
> sHTML = sHTML & join(arHTML,vbCrLf) & "</TABLE>"
> else
> sHTML = "No data was returned"
> end if
> Response.Write sHTML
> %>
>
> HTH,
> Bob Barrows
> --
> Microsoft MVP - ASP/ASP.NET
> Please reply to the newsgroup. This email account is my spam trap so I
> don't check it very often. If you must reply off-line, then remove the
> "NO SPAM"
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Align table columns with gridview columns Jacksm ASP .Net 2 11-21-2006 09:49 PM
Read CSV - string Columns - Int columns =?Utf-8?B?YmVub2l0?= ASP .Net 0 05-08-2006 02:11 PM
database columns vs. gui columns and sorting ittay.dror@gmail.com Java 5 03-04-2006 10:48 AM
CSS columns problem - faux columns don't work henrybranson@hotmail.com HTML 4 11-24-2005 10:05 AM
convert rows to columns and columns to rows helpful sql ASP .Net 0 05-19-2005 06:03 PM



Advertisments