Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,441
    Thanks
    15
    Thanked 0 Times in 0 Posts

    help formatting table according to records

    I am pasting my code below

    what I want it to show the records as follows


    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    and then 11-20 in the next row

    what it is doing now iw

    1 2
    3 4

    and so on..

    can someone help me with how to do this?

    do while not rsct.eof

    if i mod 2=1 then response.write "<tr>"
    response.write "<td>" & i & "</td><td><input type=text name=users-" & rsct("id") & " value='" & rsct("user") & "' style=color:blue></td>"
    if i mod 2<>1 then response.write "</tr>"

    userids=userids & rsct("id") & ","
    i=i+1
    rsct.movenext
    loop
    closers rsct
    if userids<>"" then userids=left(userids,len(userids)-1)
    for j=i to 20
    if j mod 2=1 then response.write "<tr>"
    response.write "<td>" & j & "</td><td><input type=text name=user value=''></td>"
    if j mod 2<>1 then response.write "</tr>"
    next
    response.write "<input type=hidden name=userids value='" & userids & "'>"
    response.write "<tr><td colspan=4 align=center><input type=submit name=submit value=Save><form>"

    response.write "</table>"

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Anything that had mod 2, change to mod 10. Assuming you wanted 1-10 in one row, 11-20 next row, etc.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Senior Coder
    Join Date
    May 2004
    Posts
    1,441
    Thanks
    15
    Thanked 0 Times in 0 Posts
    that is what i want
    but it returned

    1 2
    3
    4
    5
    6
    7
    8
    9
    10
    11 12
    13
    14
    15
    16
    17
    18
    19
    20

  • #4
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    With taking one record at a time, there's actually no possible way to put your info in a table with 1-10 in one column and 11-20 in the next column.

    However, if you put all your records into an array and then loop through the array in such a way that you grab 1 and then 11, 2 and then 12, 3 and then 13, etc., it'll be possible.

    -OR-

    You can not use a table and do something like 1-10 going into one div with a float: left on it and then 11-20 going into a second div and either float: left or float: right, depending on how you want to mark it up.

    -Shane

  • #5
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Quote Originally Posted by TheShaner View Post
    With taking one record at a time, there's actually no possible way to put your info in a table with 1-10 in one column and 11-20 in the next column.

    -Shane
    He want 1-10 in one row, 11-20 in the next row.
    Not column.
    I do it 4 at a time for my app.
    Last edited by nikkiH; 05-09-2007 at 10:41 PM.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #6
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Okay, very basic example, using northwind.

    Code:
    <html>
    <head>
    </head>
    <body>
    <table border="1" cellpadding="5">
    <tr>
    <%
    i = 1
    max = 10
    Set objConn = Server.CreateObject("ADODB.Connection")
    strConn = "Provider=sqloledb;" & _ 
             "Data Source=yourservername;" & _
             "Initial Catalog=Northwind;" & _
             "user id=yourid;password=yourpass"
    
    objConn.Open strConn  
    set objRS=server.createobject("ADODB.recordset")
    strSQL="SELECT [CustomerID], [CompanyName], [ContactName], [ContactTitle], [Address], [City], [Region], [PostalCode], [Country], [Phone], [Fax] FROM [Northwind].[dbo].[Customers]"
    objRS.Open strSQL, objConn
    objRS.movefirst
    Do while not objRS.EOF
    	response.write "<td>"
    	response.write i & ": "
    	response.write objRS("CustomerID")
    	response.write "</td>"
    	if i mod max = 0 then
    		response.write "</tr><tr>"
    	end if
    	i = i+1
    	objRS.movenext
    loop
    objRS.close
    set objRS = Nothing
    
    %>
    </tr>
    </table>
    </body>
    </html>

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #7
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    Quote Originally Posted by nikkiH View Post
    He want 1-10 in one row, 11-20 in the next row.
    Not column.
    I do it 4 at a time for my app.
    I know he said row, but it looked like he was talking about columns. Noticed he he said "what I want it to show the records as follows" and he put 1-10 in a column and then said 11-20 in the next row. Well, 1-10 were not in a row. So I assumed he meant column, seeing that "row" may have been used in the loose definition of "an arrangement of items in a line". If he's talking about horizontal rows, then yes, your method will work. But if he's referring to columns, then he needs to seek an alternative method, like what I suggested.

    -Shane

  • #8
    Senior Coder
    Join Date
    May 2004
    Posts
    1,441
    Thanks
    15
    Thanked 0 Times in 0 Posts
    your right i used the wrong word - i meant collumns..
    so the only way to do that is get rid of the tables and do a float left with css?

    or can I close the table and open a new table based on mod 10 would that work?

  • #9
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    You can use any html object and close it with mod 10 and then start your next one. Whatever html object you use, whether it be a div, table, ul, etc., you'll still have to use CSS to position them next to each other. Tables have a natural block layout, so they will not sit next to each other unless you get them floated next to each other or maybe using the display: inline property.

    Example:
    Code:
    max = 10
    i = 1
    Do While Not rsct.EOF
      If i Mod max = 1 Then Response.Write "<ul style=""float: left"">" &vbCrLf
      Response.Write "<li>" & i & ": " & rsct("user") & "</li>" &vbCrLf
      If i Mod max = 0 Then Response.Write "</ul>" &vbCrLf
      i = i + 1
      rsct.MoveNext
    Loop
    If i mod 10 <> 1 Then Response.Write "</ul>" &vbCrLf
    Explanation:
    In the loop: If a remainder of 1, it means you're starting a new column. If it's a remainder of 0, it means you're ending a column.
    Last expression: It tests to see if it just closed the ul object inside the loop. If it has a remainder of 1, it means that it just came from a remainder of 0, was incremented by 1, and then the loop ended. So if that just happened, no need to close the ul object. But if it didn't, close it.

    Hope that all makes sense and you can apply that to your code.

    -Shane
    Last edited by TheShaner; 05-10-2007 at 02:21 PM.

  • #10
    Senior Coder
    Join Date
    May 2004
    Posts
    1,441
    Thanks
    15
    Thanked 0 Times in 0 Posts
    thanks that's exactly what i did earlier based on the help from this post = thanks all of you for all your help


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •