Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 2nd, 2003, 12:08 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default Line/Row Position

How do I know what line or row I am printing on? I need to show data from a table in two columns, 26 rows. Please let me know how to go about coding this display layout.

Thanks,
Judy Sese
 
Old July 3rd, 2003, 05:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to NotNowJohn
Default

I suppose that you want to display one column from the table into 2 columns on the page. Here is the sample code:
Code:
'We have already one recordset 
Response.Write "<table cellspacing=5>"
While NOT rs.EOF
    i=i+1
    If i mod 2 Then
        Response.Write "<tr><td>" & rs.fields(0) & "</td>"
    Else
        Response.Write "<td>" & rs.fields(0) & "</td></tr>"
    End If
    rs.movenext
Wend
If i mod 2 Then Response.Write "<td>&nbsp;</td></tr>"
Response.Write "</table>"
...but the Soon is eclipsed by the Moon
 
Old July 3rd, 2003, 08:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default

Thanks for the code. It seems like this will be displaying the records in two columns one after another. I am sorry for not making my question clear, my mistake. What needs to happen is once records are read, the field will be displayed in the first column only till up to record 26. Once record number 27 is read it should be displayed at the very top of the second column right accross from the first record displayed in the 1st column.
 
Old July 3rd, 2003, 08:56 AM
Authorized User
 
Join Date: Jul 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to bosboom
Default

If you want to do this you first have to do a recordcount and divide it,
once you've got the number of records walk through the recordset and display
records until recordnumber recordcount/2 then end the column and start a new
one...

You can only do a recordcount with Static Recordsets so use the following:
Code:
set rs = Server.CreateObject("ADODB.RecordSet")
rs.open SQL, conn, adOpenStatic, adLockReadOnly, adCmdText

recordCount = rs.RecordCount
Greetz

Bosboom

 
Old July 3rd, 2003, 10:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default

The table has definitely 52 records. How do I end a column and start a new one and display beside column 1 (not below column 1). That was my problem to begin with.

Do I just code it as follows:

counter = 1
do while not rs.eof
  if counter < 27 then
  <table cellspacing......>

    <tr>
      Response.Write "<td>" & rs.fields(field1) "</tr></td>"
  </table>
  else

 ' Create another column but how do you display it beside column 1

 End if
 counter = counter + 1
 rs.movenext
loop

 I just need the code on how to create another column which will be displayed beside the first column and will have records 27 - 52. The second column will not be displayed below the 1st column but it should be beside the 1st column. I do not have any problems with how to get the recordset or number of records. I have trouble with coding two columns to display records 1 - 26 in the first column and records 27 - 52 in the second column without the second column being displayed below the 1st column.
 
Old July 4th, 2003, 01:19 AM
Authorized User
 
Join Date: Jul 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to bosboom
Default

Code:
counter = 1

response.write "<table cellspacing......><tr><td valign=top>"

do while not rs.eof
  Response.Write rs.fields(field1) & "<br>"
  if counter = 27 then
    'close column and create new one
    response.write "</td><td valign=top>"
  End if
  counter = counter + 1
  rs.movenext
loop
response.write "</td></tr></table>"
Greetz

Bosboom

 
Old July 4th, 2003, 04:04 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Are you saying you always have exactly 52 records? And you want to end up with HTML like this:
<table>
<tr><td>data from record 1</td><td>data from record 27</td></tr>
<tr><td>data from record 2</td><td>data from record 28</td></tr>
...
<tr><td>data from record 26</td><td>data from record 52</td></tr>
</table>
?

If so, the easiest way is to get the recordset into an array first, using rs.GetRows(), because its much easier to access records in any order from the array than it is from the recordset.

So you would end up with:
Code:
... code here to get the recordset
Dim RecordArray
Dim n
Const cField = 0 ' denotes the first field in the recordset
If Not rs.EOF Then
  RecordArray = rs.GetRows()
  Response.Write("<table>")
  For n = 0 to 25 ' this will be executed 26 times
    Response.Write("<tr>") ' create a new table row
    Response.Write("<td>") ' open the 1st column
    Response.Write(RecordArray(cField, n)) ' write the 1st column data
    Response.Write("</td>") ' close that 1st column
    Response.Write("<td>") ' open the 2nd column
    Response.Write(RecordArray(cField, n+26)) ' write the 2nd column data
    Response.Write("</td>") ' close that 2nd column
    Response.Write("</tr>") ' finished with that row
  Next
  Response.Write("</table>")
End If
If you have a varying number of records which you need to divide into 2 columns, the above code can easily be generalised, just let me know.

OK?
Phil
 
Old July 28th, 2003, 07:56 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default

Thanks for the help Phil. This worked great.





Similar Threads
Thread Thread Starter Forum Replies Last Post
change position of New Record row? Kimber Access VBA 3 June 27th, 2008 07:10 AM
SSTab row position dthrun VB How-To 3 March 30th, 2007 11:02 PM
How to include a new line after every row --Help srkarthik_82 General .NET 2 January 7th, 2007 09:05 PM
Identify physical position of row in gridview wirerider ASP.NET 2.0 Basics 13 October 31st, 2006 01:53 PM
Changing row position of gridview at runtime rameshsamiappan ASP.NET 2.0 Basics 0 September 25th, 2006 10:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.