TheQuestor
06-25-2009, 02:43 AM
I just can't get my head to grasp how to do this
I have my sql setup, and in it a number of skins. The skins are are able to be ranked and I need to be able to sort the skins by the rank.
I'm needing to redesign my Skins page here http://www.sshcs.com/xbmc/?mode=Skins&TM=All
and my test function output is here.
http://www.sshcs.com/xbmc/inc/eva.asp?mode=Learn
output is this
Aeon - Rank is 8.4
MediaStream - Rank is 8.33333333333333
PM3HD - Rank is 6.28571428571429
PMIII - Rank is 5.75
Serenity - Rank is 4.625
The code to get this is this.
Function Learn()
Set rsSkinNames = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT DISTINCT(Skin) FROM SkinRank"
rsSkinNames.Open strSQL, adoCon
'returns distinct skin names
Do Until rsSkinNames.EOF
TheIP = rsSkinNames("Skin")
Response.Write (""&TheIP&" - ")
Set rsRankCount = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT COUNT(Rank) AS RankCount FROM SkinRank WHERE Skin = '"&TheIP&"'"
rsRankCount.Open strSQL, adoCon
TheCount = rsRankCount("RankCount")
Set rsRankSum = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT SUM(Rank) AS RankSum FROM SkinRank WHERE Skin = '"&TheIP&"'"
rsRankSum.Open strSQL, adoCon
TheSum = rsRankSum("RankSum")
If IsNull(Int(TheSum)) OR IsNull(Int(TheCount)) Then
TheAverage = 0
Else
TheAverage = Int(TheSum) / Int(TheCount)
End If
Response.Write("Rank is "&TheAverage&" <br />")
rsSkinNames.movenext
Loop
rsSkinNames.Close
Set rsSkinNames=Nothing
rsRankCount.Close
Set rsRankCount = Nothing
rsRankSum.Close
Set rsRankSum = Nothing
End function
I know it seems that it is already sorted, but that is just the luck of the output. When I add new skins and give them a rank higher or lower they all appear at the bottom such as
Aeon - Rank is 8.4
MediaStream - Rank is 8.33333333333333
PM3HD - Rank is 6.28571428571429
PMIII - Rank is 5.75
Serenity - Rank is 4.625
TestSkin1 - Rank is 2.5
TestSkin2 - Rank is 10
I am stuck on how to sort the output by the average rank.
As in I need the one with the hightest average rank at the top, and the lowest at the bottom.
I have never been able to understand arrays, but I "FEAR" that this is one time I am going to need to use one.
Please help!!!!!
I have my sql setup, and in it a number of skins. The skins are are able to be ranked and I need to be able to sort the skins by the rank.
I'm needing to redesign my Skins page here http://www.sshcs.com/xbmc/?mode=Skins&TM=All
and my test function output is here.
http://www.sshcs.com/xbmc/inc/eva.asp?mode=Learn
output is this
Aeon - Rank is 8.4
MediaStream - Rank is 8.33333333333333
PM3HD - Rank is 6.28571428571429
PMIII - Rank is 5.75
Serenity - Rank is 4.625
The code to get this is this.
Function Learn()
Set rsSkinNames = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT DISTINCT(Skin) FROM SkinRank"
rsSkinNames.Open strSQL, adoCon
'returns distinct skin names
Do Until rsSkinNames.EOF
TheIP = rsSkinNames("Skin")
Response.Write (""&TheIP&" - ")
Set rsRankCount = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT COUNT(Rank) AS RankCount FROM SkinRank WHERE Skin = '"&TheIP&"'"
rsRankCount.Open strSQL, adoCon
TheCount = rsRankCount("RankCount")
Set rsRankSum = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT SUM(Rank) AS RankSum FROM SkinRank WHERE Skin = '"&TheIP&"'"
rsRankSum.Open strSQL, adoCon
TheSum = rsRankSum("RankSum")
If IsNull(Int(TheSum)) OR IsNull(Int(TheCount)) Then
TheAverage = 0
Else
TheAverage = Int(TheSum) / Int(TheCount)
End If
Response.Write("Rank is "&TheAverage&" <br />")
rsSkinNames.movenext
Loop
rsSkinNames.Close
Set rsSkinNames=Nothing
rsRankCount.Close
Set rsRankCount = Nothing
rsRankSum.Close
Set rsRankSum = Nothing
End function
I know it seems that it is already sorted, but that is just the luck of the output. When I add new skins and give them a rank higher or lower they all appear at the bottom such as
Aeon - Rank is 8.4
MediaStream - Rank is 8.33333333333333
PM3HD - Rank is 6.28571428571429
PMIII - Rank is 5.75
Serenity - Rank is 4.625
TestSkin1 - Rank is 2.5
TestSkin2 - Rank is 10
I am stuck on how to sort the output by the average rank.
As in I need the one with the hightest average rank at the top, and the lowest at the bottom.
I have never been able to understand arrays, but I "FEAR" that this is one time I am going to need to use one.
Please help!!!!!