Link to home
Start Free TrialLog in
Avatar of kfranck
kfranckFlag for United States of America

asked on

How do I order multiple columns in an ASP page?

I have created an ASP project where I am gathering results from a form into a MS access database. On the ASP results page I want to order multiple columns and total them across a row in a database that multiple rows. These are percentages by row that have to equal 100 percent.

The purpose of the project is to determine what a voter predicts a candidate for election will finish by percent. There are 6 candidates.

Can this query be done? If so, can you give me guidance to make this happen. Thanks.


Here is the code, which now orders by dateandtime.
 
<title>Mayor Poll Results Page</title>
</head>
<body>
<blockquote>
	<blockquote>
		<p align="center"><b><font color="#004080">
		<font face="Arial" style="font-size: 20pt">MAYOR POLL&nbsp;QUEUE<br>
		</font></font>
		<font face="Arial" color="#800000">All figures under the candidates are 
		percentage predictions</font></b></blockquote>
</blockquote>
 
<table cellspacing="2" cellpadding="2" align=center width="900"><tr>
   <th width="106"><font face="Arial" color="#FFFFFF" size="1">VOTER NAME</th>
   <th width="77"><font face="Arial" color="#FFFFFF" size="1">PHONE</font></th>
   <th width="115"><font face="Arial" color="#FFFFFF" size="1">E-MAIL</font></th> 
   <th width="57"><font face="Arial" color="#FFFFFF" size="1">BELL </font></th>
   <th width="65"><font face="Arial" color="#FFFFFF" size="1">&nbsp;COLLINS </th>
   <th width="57"><font face="Arial" color="#FFFFFF" size="1">COVEY </font></th>
   <th width="69"><font face="Arial" color="#FFFFFF" size="1">&nbsp;KONOP </th>
   <th width="55"><font face="Arial" color="#FFFFFF" size="1">&nbsp;MOODY</font></th>
   <th width="75"><font face="Arial" color="#FFFFFF" size="1">&nbsp;WILKOWSKI</th>
   <th width="134"><font face="Arial">DATE</font></th>
    
 
<%
'Dimension variables
Dim adoCon 			'Holds the Database Connection Object
Dim rsMasterRolodex			'Holds the recordset for the records in the database
Dim strSQL			'Holds the SQL query for the database
 
'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")
 
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("mayorpoll.mdb")
 
'Create an ADO recordset object
Set rsMasterRolodex = Server.CreateObject("ADODB.Recordset")
 
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT MASTER_Rolodex.* FROM MASTER_Rolodex ORDER By Dateandtime DESC;"
 
'Open the recordset with the SQL query 
rsMasterRolodex.Open strSQL, adoCon
 
Dim counter
 counter=0
'Loop through the recordset
    Do While not rsMasterRolodex.EOF
    counter=counter+1
    'Write the HTML to display the current record in the recordset
     IF 0=(counter Mod 2) Then    
   		Response.Write "<tr class='even'><td>" & rsMasterRolodex.Fields("Name") & "</td>"
	Else
		Response.Write "<tr class='odd'><td>" & rsMasterRolodex.Fields("Name") & "</td>"
	End If
    Response.Write "<td>" & rsMasterRolodex.Fields("Phone") & "</td>"
         Response.Write "<td>" & rsMasterRolodex.Fields("Email") & "</td>"
      Response.Write "<td>" & rsMasterRolodex.Fields("Bell") & "</td>"         
      Response.Write "<td>" & rsMasterRolodex.Fields("Collins") & "</td>"
      Response.Write "<td>" & rsMasterRolodex.Fields("Covey") & "</td>"
      Response.Write "<td>" & rsMasterRolodex.Fields("Konop") & "</td>"
      Response.Write "<td>" & rsMasterRolodex.Fields("Moody") & "</td>"
      Response.Write "<td>" & rsMasterRolodex.Fields("Wilkowski") & "</td>"
      Response.Write "<td style='font-size:9pt;font-family:Arial; color:#CA0002;'>" & rsMasterRolodex.Fields("Dateandtime") & "</td>"     
      Response.Write "</tr>"
        
				
	'Move to the next record in the recordset
	 rsMasterRolodex.MoveNext
	Loop
%>
</body>
</html>

Open in new window

Avatar of Daniel Wilson
Daniel Wilson
Flag of United States of America image

>>Can this query be done?

That depends on the structure of the underlying data.

Can you show us the table layout with sample data?

Thanks.
Avatar of kfranck

ASKER

Gazkid:

Per your question, I will shortly, but having problems. Please see my message on post ID:25254513. Thanks.
kfranck
Avatar of kfranck

ASKER

I have attached below the connection code. I am unclear of the sample data you request. The fields in the database are:
* Name (the voter's name)
*  Phone (he/she's phone number)
* E-mail (his e-mail address)
* Bell (candidate Bell)
* Collins (candidate Collins)
* Covey (candidate Covey)
* Konop (candidate Konop)
* Moody (candidate Moody)
* Wilkowski (candidate Wilkowski)
* Dateandtime (field for when submitted)

Again, the user enters the percentage they think the candidate will get in an election. On the results page, I want to sort by winner, etc.

kfranck
<%
 
'Dimension variables
Dim adoCon 			'Holds the Database Connection Object
Dim rsAddComments		'Holds the recordset for the new record to be added to the database
Dim strSQL			'Holds the SQL query for the database
 
'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")
 
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("mayorpoll.mdb")
 
'Create an ADO recordset object
Set rsAddComments = Server.CreateObject("ADODB.Recordset")
 
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT MASTER_Rolodex.ID,MASTER_Rolodex.Bell,MASTER_Rolodex.Collins,MASTER_Rolodex.Covey,MASTER_Rolodex.Konop, MASTER_Rolodex.Moody, MASTER_Rolodex.Wilkowski, MASTER_Rolodex.Name,MASTER_Rolodex.Dateandtime, MASTER_Rolodex.Email, MASTER_Rolodex.Phone FROM MASTER_Rolodex;"
 
'Set the cursor type we are using so we can navigate through the recordset
rsAddComments.CursorType = 2
 
'Set the lock type so that the record is locked by ADO when it is updated
rsAddComments.LockType = 3
 
'Open the MASTER_Rolodex table using the SQL query held in the strSQL varaiable
rsAddComments.Open strSQL, adoCon
 
'Tell the recordset we are adding a new record to it
rsAddComments.AddNew
 
'Add a new record to the recordset
rsAddComments.Fields("Bell") = Request.Form("ID")
rsAddComments.Fields("Bell") = Request.Form("Bell")
rsAddComments.Fields("Collins") = Request.Form("Collins")
rsAddComments.Fields("Covey") = Request.Form("Covey")
rsAddComments.Fields("Konop") = Request.Form("Konop")
rsAddComments.Fields("Moody") = Request.Form("Moody")
rsAddComments.Fields("Wilkowski") = Request.Form("Wilkowski")
rsAddComments.Fields("Name") = Request.Form("Name")
rsAddComments.Fields("Phone") = Request.Form("Phone")
rsAddComments.Fields("Email") = Request.Form("Email")
rsAddComments.Fields("Dateandtime") = "   " & Now() & " "
 
'Write the updated recordset to the database
rsAddComments.Update
 
'Reset server objects
rsAddComments.Close
Set rsAddComments = Nothing
Set adoCon = Nothing
 
'Redirect to the resultspage
Response.Redirect "Entry.asp"
%>

Open in new window

your  post

Gazkid:

Per your question, I will shortly, but having problems. Please see my message on post ID:25254513. Thanks.
kfranck

I did review and did place comment appears to work.
So output would look like:

voter       Bell         Collins Covey           Knop                 Moody         Wilkowski
________    ______       _______  ______        ______               _______       __________
KFranck         10%       10%      50%            10%                 10%            10%
DanielWilson    5%        5%       10%             5%                 5%             70%
gazdiz          10%       20%      20%            20%                 30%            20%

Open in new window

Do I have the basic data right? (omitting phone# and another detail or 2)

And you want this sorted ... how?  Which voter's record should move to the top and why?  Knowing this, we can sort it for you.

Or are you looking for an aggregation -- on average candidate X leads by ranking 33%?
Avatar of kfranck

ASKER

I like your aggregation idea of the average candidate X leading by a 33 percent ranking. If possible, I would like to leader in each row to be highlighted.

Avatar of Wayne Barron
@gazdzid
You are not suppose to talk about another Thread within another Thread.

Daniel has a good idea going on here.
Good luck Guys.

Carrzkiss
Avatar of kfranck

ASKER

Ok. I am going to repost.
I remember being new and anxious for every question to close.  carrzkiss is right, but I'm sure we call all excuse gazdid for his first couple weeks here. :)

kfranck, if we average them we're going to come out with one row with the averages.  is something like the following what you'd like to see?

Your ASP code could then change colors of the appropriate cell / div to highlight the leader ... in my example wilkowski.



Bell         Collins Covey           Knop                 Moody         Wilkowski
______       _______  ______        ______               _______       __________
8%               12%    27%            12%                 15%             33%

Open in new window

Avatar of kfranck

ASKER

Yes. This would be terrific. Thank you.
SOLUTION
Avatar of Daniel Wilson
Daniel Wilson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kfranck

ASKER

Enjoy dinner.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kfranck

ASKER

Sorry about the browser crash. I tried to put this together from what you sent me, but I am having problems. Could you look below at my coding to see if I am on the right track please. Thanks.
kfranck
<%
'Dimension variables
dim rs
set rs = adoCon.Execute(strSQL)
dim dHighest, sBGColor
dhighest = 0.0 'initialize to double
'check for high score
if rs!Bell > dHighest then dhighest = rs!Bell
if rs!Collins> dHighest then dhighest = rs!Collins
'etc.
 
'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")
 
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("mayorpoll.mdb")
 
'Create an ADO recordset object
Set rsMasterRolodex = Server.CreateObject("ADODB.Recordset")
 
strSQL = "SELECT avg(MASTER_Rolodex.Bell) as Bell, avg(MASTER_Rolodex.Collins) as Collins, Avg(MASTER_Rolodex.Covey) as Covey, Avg(MASTER_Rolodex.Konop) as Konop, Avg(MASTER_Rolodex.Moody) as Moody, avg(MASTER_Rolodex.Wilkowski)as wilkowski FROM MASTER_Rolodex;" 
 
'now output the table
response.write "<table><tr><th>Bell</th><th>Collins</th><th> ETC. </th></tr><tr>"
if rs!Bell=dhighest then sBGColor = "Gold" else sBGColor = "White"
response.write "<td BGColor=""" & sBGcolor & """>" & rs!Bell & "</td>"
if rs!Collins=dhighest then sBGColor = "Gold" else sBGColor = "White"
response.write "<td BGColor=""" & sBGcolor & """>" & rs!Collins& "</td>"
'Etc.
response.write "</tr></table>"
%>

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Looks like you very demonstrably finished it out, Carrzkiss.  Cool!
Avatar of kfranck

ASKER

Terrific! Thank you both. I am going to close this post and open a related post.
kfranck
Avatar of kfranck

ASKER

Excellent and very helpful. Thank you both.
kfranck
not a problem at all.
Glad that it worked out for you.

Carrzkiss