Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: SV: RE: SV: RE: Vote System


Message #1 by "SD-Studios" <info@s...> on Mon, 24 Sep 2001 17:26:07 +0200
But it works, right? =)

Thanks again! =)

--

Martin Johansson





-----Ursprungligt meddelande-----

Från: Sam Clohesy [mailto:sam@e...]

Skickat: den 24 september 2001 17:26

Till: ASP Databases

Ämne: [asp_databases] RE: SV: RE: Vote System





Hi Martin, it is to ensure whole numbers (again this voting system is not

very accurate..)



Thanks



Sam



-----Original Message-----

From: SD-Studios [mailto:info@s...]

Sent: 24 September 2001 16:16

To: ASP Databases

Subject: [asp_databases] SV: RE: Vote System





Thanks a lot!!! =Im not so very good at ASP, so i'd like to know what "+1"

in this string is for: averagevote =nt(totalvote/votecount)+1

--

Martin Johansson
Message #2 by "SD-Studios" <info@s...> on Tue, 25 Sep 2001 20:56:16 +0200
Thanks Kyle! =)

--

Martin Johansson





-----Ursprungligt meddelande-----

Från: Kyle Burns [mailto:kburns@c...]

Skickat: den 25 september 2001 19:37

Till: ASP Databases

Ämne: [asp_databases] RE: SV: RE: Vote System





Even better than Count(*), which will also give a performance hit, is to use

the Count function on a field that you know will contain a value (nulls are

skipped in Count) such as CodeID.  I also noticed that you are referencing

the value of the field "Average" after the recordset object is closed and

set to Nothing.  You'll need to modify the code to save this value to a

variable before closing the recordset.  I kind of shy away from using words

that could ever conceivably be a keyword when I write my SQL statements.  My

suggestion would be to have your SQL statement end up something like this:



"SELECT SUM(rating) / COUNT(codeid) AS avgRating FROM tblRating WHERE codeid

= " & choice





=================================

Kyle M. Burns, MCSD

ECommerce Technology Manager

Centra Credit Union

kburns@c...









-----Original Message-----

From: SD-Studios [mailto:info@s...]

Sent: Tuesday, September 25, 2001 11:21 AM

To: ASP Databases

Subject: [asp_databases] SV: RE: Vote System





Okay! Thanks! =)

--

Martin Johansson





-----Ursprungligt meddelande-----

Från: David Cameron [mailto:dcameron@i...]

Skickat: den 25 september 2001 01:30

Till: ASP Databases

Ämne: [asp_databases] RE: Vote System







Whoa there. There are faster ways of doing that.



First comment, never use recordcount. There is a page about it on Ken's site

(www.adopenstatic.com), but basically to get a true result you need to move

last and move first, which is a performance loss. COUNT(*) in the SQL

statement is always a better option.



<%

 dim averagevote



 Set rsd2 = Server.CreateObject("ADODB.Recordset")

 strSQL= "SELECT * FROM tblRating WHERE CodeID = " & choice

 strSQL = "SELECT SUM(rating)/COUNT(*) as Average " & _

   "FROM tblRating WHERE CodeID = " & choice

 rsd2.Open strSQL, conn, adOpenForwardOnly, adLockReadOnly

 rsd2.close

 Set rsd2 = Nothing

 averagevote = int(rsd2("Average"))

 If averagevote < 1 Then averagevote = 1



%>

                    <img src="images/<%=averagevote%>stars.gif" width="62"

height="12">



I checked the SQL string for SQL Server, it should work in Access. If not

you can return the sum and 2 different fields for Count and Sum and do the

calculation in the page.



regards

David Cameron

nOw.b2b

dcameron@i...



-----Original Message-----

From: Sam Clohesy [mailto:sam@e...]

Sent: Tuesday, 25 September 2001 1:06 AM

To: ASP Databases

Subject: [asp_databases] RE: Vote System





Something like this:



<%

 dim totalvote

 dim votecount

 dim averagevote





 Set rsd2 = Server.CreateObject("ADODB.Recordset")

 strSQL= "SELECT * FROM tblRating WHERE CodeID = " & choice

 rsd2.Open strSQL, conn, 1'adOpenForwardOnly

 votecount = rsd2.recordcount



 do while NOT rsd2.EOF

  totalvote = totalvote + rsd2("rating")

  rsd2.movenext

 loop

 if votecount > 0 then

 averagevote = int(totalvote/votecount)+1

 end if



 %>

                    <img src="images/<%=averagevote%>stars.gif" width="62"

height="12">



No doubt better way...



Thanks



Sam

















  Return to Index