If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Calculate total for recordset particular data

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-03-04, 02:08
Yutaka Yutaka is offline
Registered User
 
Join Date: Feb 2003
Posts: 20
Calculate total for recordset particular data

I got a problem on calculating the total for particular data. This is how it works, the drop down list display the data from database, same data group as one, I use distinct for that. Example, in drop down list has, A,B,C
I want to calculate how many A, B and C and put them in seperate text box.
If I choose A in drop down list, then it will display the total in textbox, if I choose B it will display the total in textbox.

<select size="1" name="list2">
.
.
<option value="<%=rs("Course_Title")%>"><%=rs("Course_Titl e")%></option>
.
.
</select>
.
.
Set rs2 = Server.CreateObject("ADODB.Recordset")
rs2.open "SELECT * FROM Registration where Course_Title = '" & Request.Form("list2") & "' and Approval_Status = 'yes' ",Conn

Dim strCount
strCount = 0
While NOT rs2.EOF AND NOT rs2.BOF
strCount = strCount + 1
rs2.MoveNext()
Wend
.
.
Approved:<input type="text" name="appcount" size="10" value="<%=strCount%>">

Hope anyone can help, thanks.
Yutaka
Reply With Quote
  #2 (permalink)  
Old 11-03-04, 02:10
Yutaka Yutaka is offline
Registered User
 
Join Date: Feb 2003
Posts: 20
forgot to add something

it display 0 in the textbox

Yutaka
Reply With Quote
  #3 (permalink)  
Old 11-03-04, 16:40
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
if all you want is the record count, do it in the SQL statement:

Code:
rs2.open "SELECT Count(*) AS RecordCount FROM Registration where Course_Title = '" & Request.Form("list2") & "' and Approval_Status = 'yes' ",Conn

Approved:<input type="text" name="appcount" size="10" value="<%=rs2("RecordCount")%>">
__________________
That which does not kill me postpones the inevitable.
Reply With Quote
  #4 (permalink)  
Old 11-03-04, 20:49
Yutaka Yutaka is offline
Registered User
 
Join Date: Feb 2003
Posts: 20
new problem

my previous code:

set rs = conn.execute("select distinct Course_Title,Date,Month from Registration")
.
.
<select size="1" name="list2">
.
.
<option value="<%=rs("Course_Title")%>"><%=rs("Course_Titl e")%></option>
.
.
</select>
.
.
Set rs2 = Server.CreateObject("ADODB.Recordset")
rs2.open "SELECT Course_Title, [Date], [Month], COUNT(Course_Title) AS [no] FROM Registration WHERE Approval_Status ='NO' GROUP BY Course_Title, [Date], [Month]",Conn

Dim strCount
strCount = 0
While NOT rs2.EOF AND NOT rs2.BOF
strCount = strCount + 1
rs2.MoveNext()
Wend
.
.
Approved:<input type="text" name="appcount" size="10" value="<%=strCount%>">

But it display one time only. Example, I got record A(NO), A(NO),A(YES),
B(NO), B(NO),B(NO),B(YES) in drop downlist.

when it display the number for A where Approval Status is "NO", it only 2, meaning got two A(NO) it counts as 1. Got 2 B(NO) counted as 1
Then it display 2 in the textbox. It should be 3 if I choose record B.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On