Displaying results from highest to lowest...

# Thread: Displaying results from highest to lowest...

1. Member
Join Date
Dec 1969
Posts
63

## Displaying results from highest to lowest...

I am creating a count for each choice by adding 1 to the variable then I am displaying the votes by calling the variable (i.e. firstTurkeyRun)<BR><BR>My question is...when displaying the results I would like to display the results by highest to lowest. <BR><BR>Is that possible to do that? <BR><BR>if rs("firstChoice") = "Turkey Run" then<BR>firstTurkeyRun = firstTurkeyRun + 1<BR>end if<BR><BR>if rs("firstChoice") = "Shopping Trip" then<BR>firstShoppingTrip = firstShoppingTrip + 1<BR>end if<BR><BR>if rs("firstChoice") = "Cub Game" then<BR>firstCubGame = firstCubGame + 1<BR>end if<BR><BR>&#039;display results<BR><BR>So if I have 6 votes in total and 3 votes are for [firstCubGame], 2 votes for [firstTurkeyRun], 1 votes for [firstShoppingTrip]<BR><BR>then the results should look like this:<BR><BR>Cub Game 3<BR>Turkey Run 2<BR>Shopping Trip 1<BR>

2. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## Let SQL do it for you.

select firstChoice, count(*) as choiceCount<BR>from table<BR>group by firstChoice<BR>order by count(*) desc

3. Junior Member
Join Date
Dec 1969
Posts
16

## RE: Displaying results from highest to lowest...

Hm.. you&#039;d ought to reconstruct your database it seems. So that you have one column with games and one column with votes. Then it&#039;d just be to sort it in the sql query.. Or maybe I&#039;ve missunderstood?<BR><BR>

4. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## Looked to me that..

.. there was only one column in the DB: firstChoice<BR><BR>From that, my guess is that the poster can just do a GROUP BY w/ a COUNT.

5. Junior Member
Join Date
Dec 1969
Posts
16

## RE: Looked to me that..

Yes, I think you&#039;re right :) Although a little reconstructing of the database seems like a good idea. Much less code in that way ;)

6. Member
Join Date
Dec 1969
Posts
63

## RE: Looked to me that..

thats true...I think I need to reconstruct the db and add fields for the choices then let SQL display the results they way I need them.

7. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## I don't think that you need..

.. to change your DB.<BR><BR>And, I think SQL will do what you need.<BR><BR>See my post:<BR>http://www.aspmessageboard.com/forum/asp.asp?M=655495&F=20&P=1

8. Member
Join Date
Dec 1969
Posts
63

## RE: I don't think that you need..

That&#039;s cool...I see what you mean.<BR><BR>BTW is there a way that I can get the counts for each Vote?<BR><BR>Thanks,<BR><BR>Chris

9. Member
Join Date
Dec 1969
Posts
63

## Nevermind...I got it.

&#060;%= rs("firstChoice") %&#062;&#060;%= rs("choiceCount") %&#062;<BR><BR>That does it...thanks so much!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•