 |
| Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." 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 Basics 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
|
|
|
|

July 31st, 2005, 03:40 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
loop value move to table
I want to move dept name to following table ?
so that when I check checkbox, dept name move
to next page how ?
I retrieve the dept name by following loop and after that dept name should be move
to following table ?
<P align=center><STRONG>Departments</STRONG> </P>
cn.connection string //....
ssql="select distinct(dept) from dept order by dept"
set rs=cn.Execute(ssql)
do while rs.eof=false
Response.Write("<option value='" & rs("dept") & "'>")
Response.Write(rs("dept") )
rs.movenext
loop
</SELECT>
<form method=post action=dept.asp id=form name=form>
<TABLE>
<TR>
<TD>ADMINISTRATION</TD>
<TD><INPUT type="checkbox" value="Response.write("dept1")" id=checkbox1 name=checkbox1>
</TD></TR>
<TR>
<TD>ARCHITECTURAL SECTION</TD>
<TD><INPUT type="checkbox" value="Response.write("dept2")" id=checkbox2 name=checkbox2>
</TD></TR>
<TR>
<TD>HIGHWAY SECTION</TD>
<TD><INPUT type="checkbox" value="Response.write("dept3")" id=checkbox3 name=checkbox3>
</TD></TR>
....
....
and so on....
</TABLE>
</form>
OR
How can use the above loop that dept name display above table ?
if Dept have 10 dept in the above table display 10 dept, if 20 dept then above table it
response.write....up to 20.. dept... how ?
Please help.
regards
Mateen
|
|

July 31st, 2005, 06:32 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
Just when I thought I understood whay you are trying to achieve, I read on and doubt myself. Sorry, Im not clear on what your needs are.
Wind is your friend
Matt
|
|

August 4th, 2005, 09:33 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
how can use the following loop in the table ?
ssql="select distinct(dept) from dept order by dept"
set rs=cn.Execute(ssql)
do while rs.eof=false
<form method=post action=dept.asp id=form name=form>
<TABLE>
<TR>
<TD>Department</TD>
<TD><INPUT type="checkbox" value="Response.write(rs("dept"))" id=checkbox1 name="Response.write(rs("dept"))">
</TD></TR>
</TABLE>
</form>
rs.movenext
loop
when I check the check box dept name move to next page ?
ie.
dept1=Request.form("checkbox1")
dept2=Reqeuet.form("checkbox2")
Response.write(dept1)
Response.write(dept2)
...
..
Mateen
|
|

August 4th, 2005, 06:24 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
;;;when I check the check box dept name move to next page ?
Why use a checkbox for this?
FYI put your <form> tag outside the loop - Actually your table tag to
BTW Its very clear you have not tryed to run the code above
I would:
<table>
<%
if not rs.EoF then
do until rs.EoF %>
<a href="dept.asp?dept=<%= trim(rs("dept")) %>"><%= trim(rs("dept")) %></a>
<% re.moveNext
loop
else
response.write "<tR><tD></td><i>No Records Found</i></tr></tr>"
end if
%>
</table>
Replace the <a href> tag with a checkbox tag to show checkboxes. Checkboxes are usually used so a user can make multiple selections, is this you need? If not you dont need checkboxes.
If it is - name your checkboxes the same, put the unique ID (not the dept name (unless you have validation in the area where a dept is added to force ALL NAMES to be unique) in the value. This way, when the form is submitted you will post a commer delimited string to the destination page. Now on this page do a:
SQL = "SELECT * FROM dept WHERE ID IN('" & request.form("chkBox") & "') ORDER BY .... ;"
Wind is your friend
Matt
|
|

August 6th, 2005, 05:23 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I try you code like this.
First Page
-----------
<form method=post action="dept.asp" id=sampleform name=sampleform>
<%
set cn=server.CreateObject("adodb.connection")
cn.ConnectionString="......."
cn.Open
ssql="select distinct(dept) from dept order by dept"
set rs=cn.Execute(ssql)
<table>
<%
if not rs.EoF then
do until rs.EoF %>
<INPUT type="checkbox" value=<%= trim(rs("dept")) %>"><%= trim(rs("dept")) %>
<% rs.moveNext
loop
else
response.write "<tR><tD></td><i>No Records Found</i></tr></tr>"
end if
%>
</table>
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
</form>
Second Page dept.asp
--------------------
in second page how can received the separate dept name from the first page ?
so that I can run separate query for each dept ?
dept1=request.form("checkBox") // ?
dept1=Request.Form("checkbox")
dept2=Request.Form("checkbox")
dept3=Request.Form("checkbox")
dept4=Request.Form("checkbox")
...
Response.Write(dept1)
Response.Write(dept2)
Response.Write(dept3)
Response.Write(dept4)
Actually I want that
--------------------
I have to display records from the table base on each dept wise.
But I could not retreived separate dept records by the loop.
set cn=server.CreateObject("adodb.connection")
set rs=server.CreateObject("adodb.recordset")
cn.ConnectionString="....."
cn.Open
// How can use your code in following queries, so that I can run queries for separate depts how ?
sql1="SELECT emp.DEPT ,emp.EMPNO ,emp.name,............ where emp.dept='"& dept1 &"'"
sql2="SELECT emp.DEPT ,emp.EMPNO ,emp.name,............ where emp.dept='"& dept2 &"'"
sql3="SELECT emp.DEPT ,emp.EMPNO ,emp.name,............ where emp.dept='"& dept3 &"'"
sql4="SELECT emp.DEPT ,emp.EMPNO ,emp.name,............ where emp.dept='"& dept4 &"'"
.....
..
set rs1=cn.Execute(sql1)
set rs2=cn.Execute(sql2)
set rs3=cn.Execute(sql3)
set rs4=cn.Execute(sql4)
...
....
Mateen
|
|

August 6th, 2005, 07:12 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
You would normally place intergers(preferably thier unique auto incrimenting primary key) in the checkbox value - not a string. A commer delimited string of integers means you only need to do one sql statement (a SELECT WHERE IN) to get all your info. If they choose many checkboxes, you way will need to do many statements, you page can work allot smarter.
Any how here is how to do what you have asked. You must put a name in your checkbox. The name remains the same from all checkboxes, this is how you get your commer delimited string. To make the code below work call your checkbox 'someName', paste the code below on your destination page (dept.asp) and run it - should be cut and paste.
<%
'your selections
request.form("someName")
dim count,ids,numOfIds
count = 0
'function to split the string into an array
Function splitOnComer(stringVar)
if isNull(stringVar) then
'do nothing
else
ids = Split(stringVar, ",", -1, 0)
numOfIds = UBound(ids) + 1
end if
End function
'split the string
splitOnComer(trim(request.form("someName")))
'your statements
if numOfIds > 0 then
do while count < numOfIds
sql="SELECT emp.DEPT ....WHERE emp.department='" & trim(ids(count)) & "';"
response.write sql & "==<br>"
count = count + 1
loop
else
'no records
end if
ids = null
%>
Wind is your friend
Matt
|
|

August 12th, 2005, 08:08 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I use the code like this.
request.form("dept")
dim count,ids,numOfIds
count = 0
Function splitOnComer(stringVar)
if isNull(stringVar) then
'do nothing
else
ids = Split(stringVar, ",", -1, 0)
numOfIds = UBound(ids) + 1
end if
End function
'split the string
splitOnComer(trim(request.form("someName")))
'your statements
if numOfIds > 0 then
do while count < numOfIds
sql="SELECT DEPT from dept WHERE dept='" & trim(ids
(count)) & "';"
response.write sql & "<br>"
count = count + 1
loop
else
'no records
end if
ids = null
set rs=cn.Execute(sql)
%>
your coding display record in second page like this.
SELECT DEPT from dept WHERE dept='ACCOUNT"';
SELECT DEPT from dept WHERE dept='ADMINISTRATION"';
..
..
it is ok, as I want.
how can execute the separate query within the loop or outside
the loop ?
I try to execute the query like this.
if numOfIds > 0 then
do while count < numOfIds
sql="SELECT DEPT from dept WHERE dept='" & trim(ids(count)) & "';"
response.write sql & "<br>"
set rs1=cn.Execute(sql1)
Response.Write(rs1("dept")) // first query records...
set rs2=cn.Execute(sql2)
Response.Write(rs2("dept")) // second query records...
set rs3=cn.Execute(sql3)
Response.Write(rs3("dept")) // third query records...
....
and so on.. all dept separate queries should be execute ?
count = count + 1
loop
else
'no records
end if
ids = null
But it give this error
"Error Type:
ADODB.Field (0x80020009)
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/tabulation/bmhours/dept.asp"
how can use counter for execute the separate query within
or out side the loop ?
ie
response.write sql(1) & "<br>"
response.write sql(2) & "<br>"
response.write sql(3) & "<br>"
...
...
so that separate query execute and separate records should be
retreive base on each query how ?
regards.
Mateen
|
|

August 14th, 2005, 07:33 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
;;;your coding display record in second page like this.
SELECT DEPT from dept WHERE dept='ACCOUNT"';
SELECT DEPT from dept WHERE dept='ADMINISTRATION"';
The query wont run like that, it should be:
SELECT DEPT from dept WHERE dept='ACCOUNT';
SELECT DEPT from dept WHERE dept='ADMINISTRATION';
;;;how can execute the separate query within the loop or outside
the loop ?
Did you think about doing it like I suggested? pass a string of integers. What if they check 100 boxes, you are going to run 100 sql statements on you destination page? Your system is not scaleable and will run poorly. Your question is interesting. The way you are using the code in the loop, did you expect that to work? If so you should reasearch how loops work. Your page lacks so much scalability I am not real keen on telling you how to get what you have suggested to work. This is how you would generate uniquely named named sql ststements.
if numOfIds > 0 then
do while count < numOfIds
sql & count ="SELECT emp.DEPT ....WHERE emp.department='" & trim(ids(count)) & "';"
response.write sql & count & "==<br>"
count = count + 1
loop
else
'no records
end if
Wind is your friend
Matt
|
|

August 21st, 2005, 08:10 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
--if they check 100 boxes, you are going to run 100 sql statements on you destination page?
you are right. it is not good.
Actually I want to calculate each dept records separately.
for this I use checkbox.
it is not necessary to use checkbox.
if my problem solve with out checkbox then well and good.
Basically I have to calcuate each dept progress.
we have 10 dept in our company.
I have to calcuate each month dept progress.
ie.
1. to run query to retrieve all dept name
2. when all dept name received then execute separate
query for each dept ?
sql1="SELECT emp.DEPT ,emp.EMPNO ,emp.name,............ where emp.dept='"& dept1 &"'"
sql2="SELECT emp.DEPT ,emp.EMPNO ,emp.name,............ where emp.dept='"& dept2 &"'"
sql3="SELECT emp.DEPT ,emp.EMPNO ,emp.name,............ where emp.dept='"& dept3 &"'"
sql4="SELECT emp.DEPT ,emp.EMPNO ,emp.name,............ where emp.dept='"& dept4 &"'"
.....
..
set rs1=cn.Execute(sql1)
set rs2=cn.Execute(sql2)
set rs3=cn.Execute(sql3)
set rs4=cn.Execute(sql4)
...
....
Without checkbox retreive all dept and execute separate
dept query how ?
regards.
Mateen
|
|

August 21st, 2005, 06:12 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
to use checkboxes or not IMO is not the problem. The problem is to many queries on your destination page. You company nay only have 10 depts now, in 10 years time they may have 100 - therefore ....
The only reason I use checkboxes is if I want a user to make multiple selections, thats the question you should ask yourself. There are a couple of questions in the posts above you failed to answer, I wont ask them again.
Does your company table have an auto incrimenting primary key field perhaps called ID? If so, place this value in the checkbox value area (make sure the checkboxes are named the same - this gives you your commer delimited string of checked ID's). Then on your destination page do a "SELECT .... WHERE ID IN ('" & request.form("chqBoxName") & "');"
IMO - Even if you dont need an auto incrimenting primary key field in a table, put it there anyway. You may need it in the future.
Wind is your friend
Matt
|
|
 |