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!

Displaying database data in columns

Status
Not open for further replies.

kloner

Programmer
May 15, 2000
79
AU
Hi all. I am trying to write some code to display a recordset in ASP, using 2 columns. Easy yeah? Hang on. The catch is I want the left column to start with "A" then work its way down .... then the top of the right column would be someting like "N" and down ....

As an example.

A G
B H
C I
D J
E K
F

I guess you need to count the RS and divide by and 2, then spit out the 1st item in a <td> and then the 'half' number and add one all the time?

Anyways if someone could help a newbie out here it would be much appreciated.

Regards

Matt
kloner


 
Hi,

I tried to think in that problem and I always reach your solution!!
Code:
<td>
<%
  num = RS.recordcount
  residue = num mod 2
  for t = 1 to ((num\2) + residue)
    Response.Write RS(&quot;Letter&quot;) & &quot;<br>&quot;
    RS.MoveNext
  next
%>
</td>
<td>
<%
  for t = ((num\2) + residue + 1) to num
    Response.Write RS(&quot;Letter&quot;) & &quot;<br>&quot;
    RS.MoveNext
  next
%>
</td>

If you need you can use Rowspan in TD tag with (num\2) + residue) value.
With this you will have (more or less) half of the letters in each column.
Hope you like it. It's not nice but it works! :)

Regards,
Luís Silva
 
Yeap that worked. I guess now a question for the 'experts'. Is the above efficient?

I heard that maybe pulling the recordset out into a two dimensional array, and then write the contents of the array to the screen may be a more 'productive' way?

How would you do this? kloner


 
I'm not so sure about the efficiency:
Code:
<%
  Dim Letter, num, residue, t
  num = RS.RecordCount
  residue = num mod 2
  Redim Letter(1 to (num + residue),1 to 2)
  for t = 1 to ((num\2) + residue)
    Letter(t, 1) = RS(&quot;Letter&quot;)
    RS.MoveNext
  next
  for t = 1 to (num\2)
    Letter(t, 2) = RS(&quot;Letter&quot;)
    RS.MoveNext
  next
%>
The other code was tested this one was writed here.
Depending how did you opened the database you can use move method.
Code:
<%
  num = RS.RecordCount
  residue = num mod 2
  for t = 1 to ((num\2) + residue)
%>
<tr>
<td>
<%
  RS.Move t
  Response.Write RS(&quot;Letter&quot;)
%>
</td>
<td>
<%
  if ((t + (num\2) + 1) > RS.RecordCount) then exit for
  RS.Move (t + num\2 + 1)
  Response.Write RS(&quot;Letter&quot;)
%>
</td>
</tr>
<%
  next
%>
This code is not tested either!

Regards,
Luís Silva
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top