Click to See Complete Forum and Search --> : loop columns
leeny
02-02-2005, 09:14 PM
i heard from my fren in order to loop columns, we have to do a mode function. is it true? is there another way we can do so? this is the hyperlink to the kind of table i wan,jus for reference. http://www.ntsmp.com/ntsmp_zl/English/EN_datapages/EN_PBT_performance_general.htm
ok, wat i have to do is to display for eg products units that are bigger than a certain number a user keys in. so for eg if the product unit is 100 and the user will to select greater than 100, i'll display all the records in that order. so, instead of loop it like that
1
1
1
1
1
1
1
i wan to loop it like that 1 1 1 1 1 1 1 1 1 1. possible?
leeny
02-03-2005, 04:08 AM
is it poss to loop vertically?
this is my code, someone help please.
Dim conn,sConnString
Set conn = Server.CreateObject("ADODB.Connection")
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("./search.mdb")
conn.open(sConnString)
sql = "Select * from PBT where item = '" &i& "'AND unit = '" &u& "'"
Set Rs = Server.CreateObject("ADODB.RecordSet")
Rs.open sql,conn
If Rs.eof then
Response.write "No records found,please try again!!!"
%>
<%Else
ex = request.form("exp")
if ex = "greater or equals to" then
sqlC = "Select Item, Grade, GradeName from SubGrade where Grade > " &g& " AND PBTID = "&rs("PBTID")&""
elseif ex = "Equals to" then
sqlC = "Select Item, Grade, GradeName from SubGrade where Grade = " &g& " AND PBTID = "&rs("PBTID")&""
else
sqlC = "Select Item, Grade, GradeName from SubGrade where Grade < " &g& " AND PBTID = "&rs("PBTID")&""
end if
Set RSC = Server.CreateObject("ADODB.RecordSet")
RSC.open sqlC,conn
response.write sqlC
%>
<form name="form1" method="post" action="">
<table width="518" border="2" cellspacing="4" cellpadding="1">
<tr>
<td width="176" rowspan="2"><div align="center"><strong>Item</strong></div></td>
<td width="147"><div align="center"><strong>Test Method</strong></div></td>
<td width="77" rowspan="2"><div align="center"><strong>Unit</strong></div></td>
<td width="78" rowspan="2"><div align="center"><strong>Test Condition</strong></div></td>
</tr>
<tr>
<td><div align="center"><strong>ASTM</strong></div></td>
</tr>
<% Do while not Rs.eof%>
<tr>
<td><div align="center"><%= i%></div></td>
<td><div align="center"><%=Rs("Method")%></div></td>
<td><div align="center"><%= u%></div></td>
<td><div align="center"><%=Rs("TestCon")%></div></td>
</tr>
</table>
<table width="260" border="0" cellspacing="4" cellpadding="4">
<% Do while not RSC.eof%>
<tr>
<td width="244" colspan="3"><div align="center"><strong><%=RSC("GradeName")%></strong></div></td>
</tr>
<tr>
<td colspan="3"><div align="center"><%=RSC("Item")%></div>
</td>
</tr>
<tr>
<td colspan="3"><div align="center"> <%=RSC("Grade")%></div></td>
</tr>
<%
RsC.movenext
Loop
%>
<%
Rs.movenext
Loop
End if
%>
</table>
leeny
02-03-2005, 05:08 AM
is it poss to loop vertically?
this is my code, someone help please.
Dim conn,sConnString
Set conn = Server.CreateObject("ADODB.Connection")
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("./search.mdb")
conn.open(sConnString)
sql = "Select * from PBT where item = '" &i& "'AND unit = '" &u& "'"
Set Rs = Server.CreateObject("ADODB.RecordSet")
Rs.open sql,conn
If Rs.eof then
Response.write "No records found,please try again!!!"
%>
<%Else
ex = request.form("exp")
if ex = "greater or equals to" then
sqlC = "Select Item, Grade, GradeName from SubGrade where Grade > " &g& " AND PBTID = "&rs("PBTID")&""
elseif ex = "Equals to" then
sqlC = "Select Item, Grade, GradeName from SubGrade where Grade = " &g& " AND PBTID = "&rs("PBTID")&""
else
sqlC = "Select Item, Grade, GradeName from SubGrade where Grade < " &g& " AND PBTID = "&rs("PBTID")&""
end if
Set RSC = Server.CreateObject("ADODB.RecordSet")
RSC.open sqlC,conn
response.write sqlC
%>
<form name="form1" method="post" action="">
<table width="518" border="2" cellspacing="4" cellpadding="1">
<tr>
<td width="176" rowspan="2"><div align="center"><strong>Item</strong></div></td>
<td width="147"><div align="center"><strong>Test Method</strong></div></td>
<td width="77" rowspan="2"><div align="center"><strong>Unit</strong></div></td>
<td width="78" rowspan="2"><div align="center"><strong>Test Condition</strong></div></td>
</tr>
<tr>
<td><div align="center"><strong>ASTM</strong></div></td>
</tr>
<% Do while not Rs.eof%>
<tr>
<td><div align="center"><%= i%></div></td>
<td><div align="center"><%=Rs("Method")%></div></td>
<td><div align="center"><%= u%></div></td>
<td><div align="center"><%=Rs("TestCon")%></div></td>
</tr>
</table>
<table width="260" border="0" cellspacing="4" cellpadding="4">
<% Do while not RSC.eof%>
<tr>
<td width="244" colspan="3"><div align="center"><strong><%=RSC("GradeName")%></strong></div></td>
</tr>
<tr>
<td colspan="3"><div align="center"><%=RSC("Item")%></div>
</td>
</tr>
<tr>
<td colspan="3"><div align="center"> <%=RSC("Grade")%></div></td>
</tr>
<%
RsC.movenext
Loop
%>
<%
Rs.movenext
Loop
End if
%>
</table>
Bullschmidt
02-09-2005, 08:22 AM
Well here is a snippet of code I've used to create a string of e-mail addresses. And of course if one did a Response.Write strUserEmails it would print out horizontally:
' *** Build strUserEmails - E-mail addresses separated by comma and space.
' Set sql.
strSQL = "SELECT UserEmail "
strSQL = strSQL & "FROM tblUser "
strSQL = strSQL & "WHERE (1=1) "
strSQL = strSQL & " AND (UserEmail Is Not Null) "
strSQL = strSQL & " AND (UserIsEmailNotif=True) "
strSQL = strSQL & "ORDER BY UserLName, UserFName "
' Open rs.
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn
' If no recs.
If objRS.EOF Then
' Close rs.
objRS.Close
Set objRS = Nothing
Exit Function
Else
' Put recs into array for speed.
arrayRS = objRS.GetRows
' Close rs.
objRS.Close
Set objRS = Nothing
' Init.
strUserEmails = ""
' Loop thru rows (i.e. recs).
For I = 0 To UBound(arrayRS, 2)
' Set var using each fld's col num.
UserEmail = arrayRS(0, I)
strUserEmails = strUserEmails & ", " & UserEmail
Next
' Remove initial comma and space.
strUserEmails = Right(strUserEmails, Len(strUserEmails) - 2)
End If
Bullschmidt
02-09-2005, 08:23 AM
And as a related note you might find these of interest:
Classic ASP Design Tips - Multiple Records in Each Row
http://www.bullschmidt.com/devtip-multiplerecsineachrow.asp
How do I change a list into a set of table rows and columns?
http://www.aspfaq.com/show.asp?id=2247
Code is a little complicated as can handle any number of columns.