...

View Full Version : help formatting table according to records



esthera
05-09-2007, 08:41 PM
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>"

nikkiH
05-09-2007, 08:51 PM
Anything that had mod 2, change to mod 10. Assuming you wanted 1-10 in one row, 11-20 next row, etc.

esthera
05-09-2007, 09:12 PM
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

TheShaner
05-09-2007, 09:58 PM
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

nikkiH
05-09-2007, 11:39 PM
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.

nikkiH
05-09-2007, 11:56 PM
Okay, very basic example, using northwind.


<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>

TheShaner
05-10-2007, 03:07 AM
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

esthera
05-10-2007, 06:52 AM
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?

TheShaner
05-10-2007, 03:15 PM
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:

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

esthera
05-10-2007, 03:17 PM
thanks that's exactly what i did earlier based on the help from this post = thanks all of you for all your help



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum