sql1 = "select destinct hotbillederID from hotstemmer" destSel = conn.execute("sql1")
if not destSel.eof then sql2 = "select sum(point) from hotstemmer where hotbillederID = '" & destSel("hotbillederID") & "'" sumselect = conn.execute("sql2") if not sumselect.eof then response.write sumselect("") / destsel.total end if end if
først finder du hver enkelt forskellige hotbillederID-numre... derved har du en række unikke... id'er som du henter summen af søjlen fra...hvor søjlen er hotbillederID...
Du må først og fremmest undskylde at jeg ikke lige har været her :-) Men jeg syntes ikke at jeg kan få det til at virke, det er en mysql db jeg har. Den laver følgende fejl:
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'EOF'
Jeg kan simpelhent ikke få det til at virke. Det eks du har er også med en access db og ikke en mysql db. Kan det ikke have noget at sige? Den kommer med denne fejl:
Microsoft OLE DB Provider for ODBC Drivers error '80040e09'
[TCX][MyODBC]Der er en fejl i SQL syntaksen nær 'WHERE hotbillederID = 58' på linje 1
/profil/hotbilleder/Default.asp, line 81
Sådan her ser min kode ud nu: 'make 1st SQL strSQL = "SELECT DISTINCT hotbillederID FROM hotstemmer" Set DestincSelection = Conn.Execute(strSQL) Do 'make 2nd SQL strSQL2 = "SELECT SUM(point) FROM hotstemmer " strSQL2 = strSQL2 & " WHERE hotbillederID = " & DestincSelection("hotbillederID") & "" Set SumSelection = Conn.Execute(strSQL2)
'make 3rd SQL strSQL3 = "SELECT * FROM hotstemmer " strSQL3 = strSQL2 & " WHERE hotbillederID = " & DestincSelection("hotbillederID") & "" Set NumSelection = Conn.Execute(strSQL3)
Jeg syntes ikke at det ser rigtig ud... Jeg tror ikke at vi er enige mht hvordan at det skal udskrives. Det skal knu være én placering, lige som her på eksperten. Hvor at man kan se sin egen placering oppe i venstre hjørne: Placering: 7.260
Men i hvert fald så vil jeg tro at der skal et ID ind et sted for at definere hvilket billede placeringen høre til...?
strSQL = "SELECT hotbillederID FROM hotstemmer ORDER BY point desc" Set DestincSelection = Conn.Execute(strSQL) Do strSQL2 = "SELECT * FROM hotstemmer " strSQL2 = strSQL2 & " WHERE hotbillederID = " & DestincSelection("hotbillederID") & "" Set SumSelection = Conn.Execute(strSQL2) do SumSelection_Sum = SumSelection_Sum + SumSelection("point") SumSelection.MoveNext loop while not SumSelection.EOF
strSQL3 = "SELECT * FROM hotstemmer " strSQL3 = strSQL3 & " WHERE hotbillederID = " & DestincSelection("hotbillederID") & "" Set NumSelection = Conn.Execute(strSQL3) do NumSelection_TotalRecords = NumSelection_TotalRecords + 1 NumSelection.MoveNext Loop While not NumSelection.EOF
IF DestincSelection("hotbillederID") <> TempID THEN MegaString = MegaString & DestincSelection("hotbillederID") & "_" & Avarage & "¤" End if TempID = DestincSelection("hotbillederID")
DestincSelection.MoveNext Loop While Not DestincSelection.EOF
MegaArray = Split(MegaString,"¤") For ArrayCount = 0 to UBound(MegaArray) -1 Rows = Split(MegaArray(ArrayCount),"_") if inStr(Rows(0),HER SKAL HotBillederID's ID indsættes- fx Session("ID") ) Then Response.Write Rows(0) & "..." & Rows(1) & "<br>" end if Next
strSQL = "SELECT hotbillederID FROM hotstemmer ORDER BY point desc" Set DestincSelection = Conn.Execute(strSQL) Do strSQL2 = "SELECT * FROM hotstemmer " strSQL2 = strSQL2 & " WHERE hotbillederID = " & DestincSelection("hotbillederID") & "" Set SumSelection = Conn.Execute(strSQL2) do SumSelection_Sum = SumSelection_Sum + SumSelection("point") SumSelection.MoveNext loop while not SumSelection.EOF
strSQL3 = "SELECT * FROM hotstemmer " strSQL3 = strSQL3 & " WHERE hotbillederID = " & DestincSelection("hotbillederID") & "" Set NumSelection = Conn.Execute(strSQL3) do NumSelection_TotalRecords = NumSelection_TotalRecords + 1 NumSelection.MoveNext Loop While not NumSelection.EOF
sådan her... vil placeringen ikke være akkumuleret :
strSQL = "SELECT hotbillederID FROM hotstemmer ORDER BY point desc" Set DestincSelection = Conn.Execute(strSQL) Do strSQL2 = "SELECT * FROM hotstemmer " strSQL2 = strSQL2 & " WHERE hotbillederID = " & DestincSelection("hotbillederID") & "" Set SumSelection = Conn.Execute(strSQL2) do SumSelection_Sum = SumSelection_Sum + SumSelection("point") SumSelection.MoveNext loop while not SumSelection.EOF
strSQL3 = "SELECT * FROM hotstemmer " strSQL3 = strSQL3 & " WHERE hotbillederID = " & DestincSelection("hotbillederID") & "" Set NumSelection = Conn.Execute(strSQL3) do NumSelection_TotalRecords = NumSelection_TotalRecords + 1 NumSelection.MoveNext Loop While not NumSelection.EOF
IF DestincSelection("hotbillederID") <> TempID THEN MegaString = MegaString & DestincSelection("hotbillederID") & "_" & Avarage & "¤" End if TempID = DestincSelection("hotbillederID")
DestincSelection.MoveNext Loop While Not DestincSelection.EOF
MegaArray = Split(MegaString,"¤") For ArrayCount = 0 to UBound(MegaArray) -1 Rows = Split(MegaArray(ArrayCount),"_") if Rows(0) <> tmp then Placering = Placering + 1 end if tmpID = Rows(0) if inStr(Rows(0),"65") Then Response.WRite "Placering: " & Placering & "<br>" Response.Write "HotbillederID: " & Rows(0) & " <br> Point: " & Rows(1) & "<br>" end if Next
NumSelection_TotalRecords = 0 SumSelection_Sum = 0 DistinctSelection.MoveNext loop while not DistinctSelection.EOF 'sortering For i = UBound(HotBillederArray) - 1 To 1 Step - 1 MaxVal = HotBillederArray(i,1) MaxIndex = i
For j = 0 To i If HotBillederArray(j,1) > MaxVal Then MaxVal = HotBillederArray(j,1) MaxIndex = j End If Next
If MaxIndex < i Then HotBillederArray(MaxIndex,1) = HotBillederArray(i,1) HotBillederArray(MaxIndex,0) = HotBillederArray(i,0) HotBillederArray(i,1) = MaxVal HotBillederArray(i,0) = MaxVal End If Next For ReadArr = 0 to 500 If HotBillederArray(ReadArr,1) <> "" then placering = placering + 1 PlaceringArr(placering) = HotBillederArray(ReadArr,1) end if Next '--------------------------- strSQL4 = "SELECT * FROM hotstemmer " strSQL4 = strSQL4 & " WHERE hotbillederID = " & 54 & "" Set SumSelection2 = Conn.Execute(strSQL4) do SumSelection2_Sum = SumSelection2_Sum + SumSelection2("point") SumSelection2.MoveNext loop while not SumSelection2.EOF
strSQL5 = "SELECT * FROM hotstemmer " strSQL5 = strSQL5 & " WHERE hotbillederID = " & 54 & "" Set NumSelection2 = Conn.Execute(strSQL5) do NumSelection2_TotalRecords = NumSelection2_TotalRecords + 1 NumSelection2.MoveNext Loop While not NumSelection2.EOF
For TotalPlacering = 0 to 500 if PlaceringArr(TotalPlacering) = Avarage2 Then Response.Write "Placering: " & TotalPlacering & ": " & PlaceringArr(TotalPlacering) & " Point <br>" end if Next
Scriptet virker som det skal :-) Dog har jeg et lille problem når jeg sætter det ind. Jeg lister mine billeder under hinanden med en masse data til burgeren, den viser fint den første loop, men når den skal lave nr to loop så laver den fejl i linje 70, og der står der: Dim HotBillederArray(500,1)
Alt i scripted som står over '--------------------------- må kun køres een gang !... derfor skal den del af scriptet placeres i toppen af din asp-side . og uden for loops og løkker...
det der står under kan du placere i loops, eller der hvor dit billede hentes...
jeg har dog selv opdaget det problem, at hvis 2 billeder har samme gennesnitsværdi, vil begge placeringer blive vist... hvilket er lidt skod...
fx.. hvis billedID = 54 og 75, begge har 2 stemmer, og begge stemmer er på 7 og 8, vil 54* og 75* have 7,5 i snit...
og følgende blive vist:
Placering: 2: 7,5 Point Placering: 3: 7,5 Point
men det er til at leve med... du kan evt. lukke for nummer 2 visning med..
For TotalPlacering = 0 to 500 If visning = 0 then if PlaceringArr(TotalPlacering) = Avarage2 Then Response.Write "Placering: " & TotalPlacering & ": " & PlaceringArr(TotalPlacering) & " Point <br>" end if end if visning = visning + 1 Next visning = 0
For TotalPlacering = 0 to 500 if PlaceringArr(TotalPlacering) = Avarage2 Then If visning = 0 then Response.Write "Placering: " & TotalPlacering & ": " & PlaceringArr(TotalPlacering) & " Point <br>" end if visning = visning + 1 end if Next visning = 0
NumSelection_TotalRecords = 0 SumSelection_Sum = 0 DistinctSelection.MoveNext loop while not DistinctSelection.EOF 'sortering For i = UBound(HotBillederArray) - 1 To 1 Step - 1 MaxVal = HotBillederArray(i,1) MaxIndex = i
For j = 0 To i If HotBillederArray(j,1) > MaxVal Then MaxVal = HotBillederArray(j,1) MaxIndex = j End If Next
If MaxIndex < i Then HotBillederArray(MaxIndex,1) = HotBillederArray(i,1) HotBillederArray(MaxIndex,0) = HotBillederArray(i,0) HotBillederArray(i,1) = MaxVal HotBillederArray(i,0) = MaxVal End If Next For ReadArr = 0 to 500 If HotBillederArray(ReadArr,1) <> "" then placering = placering + 1 PlaceringArr(placering) = HotBillederArray(ReadArr,1) end if Next '---- PLACERING DEL 1 SLUT------
SQLhotbilleder = "select * from hotbilleder where profilerID=" & session("id") set RShotbilleder = conn.execute(SQLhotbilleder) do while not RShotbilleder.EOF%> <br> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr align="left" valign="top"> <td width="22%"><img src="/images/hotbilleder/thumb/<%=RShotbilleder("billede")%>" width="100"><br> <a href="ret.asp?id=<%=RShotbilleder("id")%>" onclick="NewWindow(this.href,'Copyright','450','150','no','center');return false">Ret</a> - <a href="slet.asp?id=<%=RShotbilleder("id")%>" onclick="NewWindow(this.href,'Copyright','450','150','no','center');return false">Slet</a></td> <td width="3%"> </td> <td width="41%">Tilføjet: <%=DanskDatoTid(RShotbilleder("dato"))%><br> Status: <%if RShotbilleder("godkendt") = "0" then%> <span style="color: #993333">Venter på godkendelse!</span> <%else%> <span style="color: #009900">Godkendt</span> <%end if
SQLgen2 = "SELECT COUNT(*) AS count FROM hotstemmer where hotbillederID = " & RShotbilleder("id")&"" Set RSgen2 = Conn.Execute(SQLgen2)
if not RSgen2("count") = "0" then SQLgen1 = "SELECT SUM(point) FROM hotstemmer where hotbillederID = " & RShotbilleder("id")&"" Set RSgen1 = Conn.Execute(SQLgen1)
gennemsnit = RSgen1(0)/RSgen2("count") end if %> <br> Score: <%if not RSgen2("count") = "0" then%> <%Response.Write(FormatNumber(gennemsnit,2)) %> (<%=RSgen2("count")%> stemmer)<%else%> Ingen stemmer!<%end if%><br> <% if not RSgen2("count") = "0" then
'---- PLACERING DEL 2 START------ strSQL4 = "SELECT * FROM hotstemmer " strSQL4 = strSQL4 & "WHERE hotbillederID = " & RShotbilleder("id") & "" Set SumSelection2 = Conn.Execute(strSQL4) do SumSelection2_Sum = SumSelection2_Sum + SumSelection2("point") SumSelection2.MoveNext loop while not SumSelection2.EOF
strSQL5 = "SELECT * FROM hotstemmer " strSQL5 = strSQL5 & " WHERE hotbillederID = " & RShotbilleder("id") & "" Set NumSelection2 = Conn.Execute(strSQL5) do NumSelection2_TotalRecords = NumSelection2_TotalRecords + 1 NumSelection2.MoveNext Loop While not NumSelection2.EOF
For TotalPlacering = 0 to 500 if PlaceringArr(TotalPlacering) = Avarage2 Then If visning = 0 then Response.Write "Placering: " & TotalPlacering & ": " & PlaceringArr(TotalPlacering) & " Point <br>" end if visning = visning + 1 end if Next visning = 0 else response.Write("MIN. 20 stemmer") end if '---- PLACERING DEL 2 SLUT------ %> <br> <br> <a href="/default.asp?mode=picture&pictureID=<%=RShotbilleder("id")%>">Se billede</a><br> <a href="/profil/hotbilleder/sestemmer/?id=<%=RShotbilleder("id")%>">Se stemmer</a> </td> <td width="34%" valign="bottom">
<% Sql = "SELECT count(*) as '0' FROM hotstemmer WHERE profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS0 = conn.execute(sql)
if not RS0("0") = "0" then Sql = "SELECT count(*) as '1' FROM hotstemmer WHERE point = '1' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS1 = conn.execute(sql) Sql = "SELECT count(*) as '2' FROM hotstemmer WHERE point = '2' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS2 = conn.execute(sql) Sql = "SELECT count(*) as '3' FROM hotstemmer WHERE point = '3' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS3 = conn.execute(sql) Sql = "SELECT count(*) as '4' FROM hotstemmer WHERE point = '4' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS4 = conn.execute(sql) Sql = "SELECT count(*) as '5' FROM hotstemmer WHERE point = '5' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS5 = conn.execute(sql) Sql = "SELECT count(*) as '6' FROM hotstemmer WHERE point = '6' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS6 = conn.execute(sql) Sql = "SELECT count(*) as '7' FROM hotstemmer WHERE point = '7' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS7 = conn.execute(sql) Sql = "SELECT count(*) as '8' FROM hotstemmer WHERE point = '8' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS8 = conn.execute(sql) Sql = "SELECT count(*) as '9' FROM hotstemmer WHERE point = '9' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS9 = conn.execute(sql) Sql = "SELECT count(*) as '10' FROM hotstemmer WHERE point = '10' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS10 = conn.execute(sql)
NumSelection_TotalRecords = 0 SumSelection_Sum = 0 DistinctSelection.MoveNext loop while not DistinctSelection.EOF 'sortering For i = UBound(HotBillederArray) - 1 To 1 Step - 1 MaxVal = HotBillederArray(i,1) MaxIndex = i
For j = 0 To i If HotBillederArray(j,1) > MaxVal Then MaxVal = HotBillederArray(j,1) MaxIndex = j End If Next
If MaxIndex < i Then HotBillederArray(MaxIndex,1) = HotBillederArray(i,1) HotBillederArray(MaxIndex,0) = HotBillederArray(i,0) HotBillederArray(i,1) = MaxVal HotBillederArray(i,0) = MaxVal End If Next 'Sortering Slut 'Læs det sorterede Array og sæt dem i en pæn orden For ReadArr = 0 to 500 If HotBillederArray(ReadArr,1) <> "" then placering = placering + 1 PlaceringArr(placering) = HotBillederArray(ReadArr,1) end if Next '---- PLACERING DEL 1 SLUT------
SQLgen2 = "SELECT COUNT(*) AS count FROM hotstemmer where hotbillederID = " & RShotbilleder("id")&"" Set RSgen2 = Conn.Execute(SQLgen2) if not RSgen2("count") = "0" then SQLgen1 = "SELECT SUM(point) FROM hotstemmer where hotbillederID = " & RShotbilleder("id")&"" Set RSgen1 = Conn.Execute(SQLgen1)
gennemsnit = RSgen1(0)/RSgen2("count") end if %> <br> <% if not RSgen2("count") = "0" then Response.Write "Score: " Response.Write FormatNumber(gennemsnit,2) Response.Write "(" & RSgen2("count") & " stemmer)" Else Response.Write "Ingen stemmer!" End If %><br> <% if not RSgen2("count") = "0" then
'---- PLACERING DEL 2 START------ strSQL4 = "SELECT * FROM hotstemmer " strSQL4 = strSQL4 & "WHERE hotbillederID = " & RShotbilleder("id") & "" Set SumSelection2 = Conn.Execute(strSQL4) do SumSelection2_Sum = SumSelection2_Sum + SumSelection2("point") SumSelection2.MoveNext loop while not SumSelection2.EOF
strSQL5 = "SELECT * FROM hotstemmer " strSQL5 = strSQL5 & " WHERE hotbillederID = " & RShotbilleder("id") & "" Set NumSelection2 = Conn.Execute(strSQL5) do NumSelection2_TotalRecords = NumSelection2_TotalRecords + 1 NumSelection2.MoveNext Loop While not NumSelection2.EOF
For TotalPlacering = 0 to 500 If PlaceringArr(TotalPlacering) = Avarage2 Then Response.Write "Placering: " & TotalPlacering & ": " & PlaceringArr(TotalPlacering) & " Point <br>" Exit For end if Next Else response.Write("MIN. 20 stemmer") End if '---- PLACERING DEL 2 SLUT------ %> <br> <br> <a href="/default.asp?mode=picture&pictureID=<%=RShotbilleder("id")%>">Se billede</a><br> <a href="/profil/hotbilleder/sestemmer/?id=<%=RShotbilleder("id")%>">Se stemmer</a> </td> <td width="34%" valign="bottom">
<% Sql = "SELECT count(*) as '0' FROM hotstemmer WHERE profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS0 = conn.execute(sql)
if not RS0("0") = "0" then Sql = "SELECT count(*) as '1' FROM hotstemmer WHERE point = '1' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS1 = conn.execute(sql) Sql = "SELECT count(*) as '2' FROM hotstemmer WHERE point = '2' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS2 = conn.execute(sql) Sql = "SELECT count(*) as '3' FROM hotstemmer WHERE point = '3' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS3 = conn.execute(sql) Sql = "SELECT count(*) as '4' FROM hotstemmer WHERE point = '4' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS4 = conn.execute(sql) Sql = "SELECT count(*) as '5' FROM hotstemmer WHERE point = '5' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS5 = conn.execute(sql) Sql = "SELECT count(*) as '6' FROM hotstemmer WHERE point = '6' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS6 = conn.execute(sql) Sql = "SELECT count(*) as '7' FROM hotstemmer WHERE point = '7' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS7 = conn.execute(sql) Sql = "SELECT count(*) as '8' FROM hotstemmer WHERE point = '8' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS8 = conn.execute(sql) Sql = "SELECT count(*) as '9' FROM hotstemmer WHERE point = '9' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS9 = conn.execute(sql) Sql = "SELECT count(*) as '10' FROM hotstemmer WHERE point = '10' AND profilerID = "& session("id") &" AND hotbillederID = "& RShotbilleder("id") &"" Set RS10 = conn.execute(sql)
set RS = conn.execute("Select hotbillederID,SUM(POINT) from HotStemmer group by hotbillederID order by count(POINT) desc ")
Do while not rs.eof placering = placering + 1 if rs("hotbillederID") = "den du vil undersøge" then response.write placering & "alt det andet gejl" end if loop
hvis du har brug for flere data er det intet problem !!
Ja, det er da lidt tid siden :-) hehe Jeg fik løst det ved at få lavet en funktion. Men jeg syntes at det er kanon at du lavede det selv om at spm´et var lukket! :o)
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.