ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 23rd, 2003, 10:38 AM
storm_mind storm_mind is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 45 storm_mind User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 57 m 14 sec
Reputation Power: 5
poll & count syntax

My poll's database has a table called "votos". This table as 3 fields: "date", "ip" and "voto". In the field "voto" I will record the option chosen in the previous form (this input may be "01", "02", "03",..., "19" or "20").
Now I want to show the results and for that, I must count the number of time that each option is displayed. Can anyone tell me the count syntax for that? I've tried to change an example I've found in internet, but didn,t achieve it... The code is:

<%
accessdb="/panteismo/db/poll.mdb"
cn="driver={Microsoft Access Driver (*.mdb)};"
cn=cn & "dbq=" & server.mappath(accessdb)
set rs = server.createobject("ADODB.Recordset")

sql=sql & "select count(01) as 01,"
sql=sql & "select count(02) as 02,"
sql=sql & "select count(03) as 03,"
(...)
sql=sql & "select count(19) as 19,"
sql=sql & "select count(20) as 20,"
sql= sql & "count(*) AS total_votes "
sql= sql & "FROM votos"
rs.Open sql, cn
total1=rs ("01")
total2=rs ("02")
total3=rs ("03")
(...)
total19=rs ("19")
total20=rs ("20")
count=rs ("total_votes")
%>

Then I have:

<tr>
<td width="195"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><span style="font-size:10.0pt;font-family:Verdana">Agnosticismo</span></font></td>
<td width="295"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><span style="font-size:10.0pt;font-family:Verdana"><img src="cores/red.jpg" height="10" width="<%= formatnumber((total1/count)*200,0) %>"> <%= total1 %> (<%= formatnumber((total1/count)*100) %>%)</span></font></td>
</tr>

I guess the problem is in count syntax, but don´t know how to fix it...

Luís

Reply With Quote
  #2  
Old October 23rd, 2003, 03:49 PM
kkong's Avatar
kkong kkong is offline
Monkey Magic
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: UK
Posts: 103 kkong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to kkong
Hi,

Are you getting any error messages when running your code?

Looking at your sql string I don't know if that is allowed but I don't use MS Access so can't be sure on that.

You can tidy your sql up by doing something like this:

Code:
select Distinct Count(voto) as VotoNum, voto 
from votos
group by voto


Again not sure if the above will work in access.. works fine in oracle. Two problems with using the above though, the first one is if any row has no numbers then a row will not be returned the second is there is no total figure.

Total figure is easy to get by going through the recordset and adding up the column.

Code:
<%
Dim lnTotal
Do While NOT rs.EOF
  lnTotal = lnTotal + rs("VotoNum")
 rs.MoveNext
Loop
%>


Then to output the data you just need to go through your rs similar to the above just displaying the VotoNum field where you want it.

You could code for the other problem in the loop when your displaying the data but you would probably have to hard code it to work...

hope this helps.

Kong.

Reply With Quote
  #3  
Old October 24th, 2003, 10:32 AM
storm_mind storm_mind is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 45 storm_mind User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 57 m 14 sec
Reputation Power: 5
I've used:

<%
accessdb="/panteismo/db/poll.mdb"
cn="driver={Microsoft Access Driver (*.mdb)};"
cn=cn & "dbq=" & server.mappath(accessdb)
set rs = server.createobject("ADODB.Recordset")

select Distinct Count(voto) as VotoNum, voto
from votos
group by voto

and receive the following message error:

Microsoft VBScript compilation error '800a03fd'

Expected 'Case'

/panteismo/pollresults.asp, line 130

select Distinct Count(voto) as VotoNum, voto
-------^

Any sugestion?

Luis

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > poll & count syntax


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT