08. november 2001 - 17:02Der er
23 kommentarer og 3 løsninger
asp detaljer
Jeg har en liste med nogle point og navne. Listen sorteres udfra pointsne og kan max indholde 10 poster.
Jeg vil gerne have koden således at når der tilføjes mere end 10 poster så slettes den post med de laveste points. Og så vil jeg gerne have at de højeste point står øverst.
metric > virker ikke der kommer stadig mere end 10.
Var sådan du mente?
Conn.Execute(\"INSERT INTO tabel (thescore, thename) VALUES (\'\" & Request.Form(\"score\") & \"\',\'\" & Request.Form(\"name\") & \"\') \") Conn.Execute(\"DELETE FROM tabel WHERE NOT ID IN (SELECT TOP 10 ID FROM tabel ORDER BY thescore DESC)\")
Det burde altså virke.. Det har ikke noget at gøre med at din Conn ikke bliver lukket.. prøv lidt igen, for ovenstående query virker altså :) Måske kan Access ikke fatte query\'en rigtigt - (brug SQL Server ;)
<% Set Conn = Server.CreateObject(\"ADODB.Connection\") Conn.Open \"DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=\" & Server.MapPath(\"db.mdb\") Conn.Execute(\"INSERT INTO tabel (thescore, thename) VALUES (\'\" & Request.Form(\"score\") & \"\',\'\" & Request.Form(\"name\") & \"\') \") Set RS=Conn.Execute(\"SELECT TOP 10 * FROM tabel ORDER BY thescore DESC\")
%>
<body bgcolor=ffffff> <table> <tr><td>Score</td><td>Navn</td></tr> <% dim i i = 0 do until RS.eof or i = 10%> <tr><td><%=rs(\"thescore\")%></td><td><%=rs(\"thename\")%></td></tr> <% RS.movenext i = i + 1 loop %> </table> </body>
if Request.Form(\"score\") <> \"\" then Conn.Execute(\"INSERT INTO tabel (thescore, thename) VALUES (\" & Request.Form(\"score\") & \",\'\" & Request.Form(\"name\") & \"\') \") set rs = Conn.Execute(\"SELECT Count(ID) as AntalID FROM tabel\") antalRS = rs(\"antalID\") set rs = Conn.Execute(\"SELECT * FROM tabel ORDER BY thescore, ID\") do while antalRS > 10 Conn.Execute(\"DELETE FROM tabel WHERE ID = \" & rs(\"ID\")) rs.movenext antalRS = antalRS - 1 loop end if
%> <html> <head></head> <body bgcolor=ffffff> <table> <tr><td>Score</td><td>Navn</td></tr> <% Set RS=Conn.Execute(\"SELECT * FROM tabel ORDER BY thescore DESC\") do until RS.eof %> <tr><td><%=rs(\"thescore\")%></td><td><%=rs(\"thename\")%></td></tr> <% RS.movenext loop %> </table>
if Request.Form(\"score\") <> \"\" then Conn.Execute(\"INSERT INTO tabel (thescore, thename, dato) VALUES (\" & Request.Form(\"score\") & \",\'\" & Request.Form(\"name\") & \"\', #\"&Date&\"#)\") set rs = Conn.Execute(\"SELECT Count(ID) as AntalID FROM tabel\") antalRS = rs(\"antalID\") set rs = Conn.Execute(\"SELECT * FROM tabel ORDER BY thescore, ID\") do while antalRS > 10 Conn.Execute(\"DELETE FROM tabel WHERE ID = \" & rs(\"ID\")) rs.movenext antalRS = antalRS - 1 loop end if
%> <html> <head></head> <body bgcolor=ffffff> <table> <tr><td>Plads</td><td>Score</td><td>Navn</td><td>Dato</td></tr> <% Set RS=Conn.Execute(\"SELECT format(dato,\'dd-mm-yyyy\') as DatoStr, * FROM tabel ORDER BY thescore DESC\") Counter = 1 do until RS.eof %> <tr><td><%=Counter%></td> <td><%=rs(\"thescore\")%></td> <td><%=rs(\"thename\")%></td> <td><%=rs(\"DatoStr\")%></td> </tr> <% Counter = Counter + 1 RS.movenext loop %> </table>
if Request.Form(\"score\") <> \"\" then Conn.Execute(\"INSERT INTO tabel (thescore, thename, dato) VALUES (\" & Request.Form(\"score\") & \",\'\" & Request.Form(\"name\") & \"\', #\"&Date&\"#)\") set rs = Conn.Execute(\"SELECT Count(ID) as AntalID FROM tabel\") antalRS = rs(\"antalID\") set rs = Conn.Execute(\"SELECT * FROM tabel ORDER BY thescore, ID\") do while antalRS > 10 Conn.Execute(\"DELETE FROM tabel WHERE ID = \" & rs(\"ID\")) rs.movenext antalRS = antalRS - 1 loop end if
%> <html> <head></head> <body bgcolor=ffffff> <table> <tr><td>Plads</td><td>Score</td><td>Navn</td><td>Dato</td></tr> <% Set RS=Conn.Execute(\"SELECT format(dato,\'dd-mm-yyyy\') as DatoStr, * FROM tabel ORDER BY thescore DESC\") Counter = 1 do until RS.eof %> <tr><td><%=Counter%></td> <td><%=rs(\"thescore\")%></td> <td><%=rs(\"thename\")%></td> <td><%=rs(\"DatoStr\")%></td> </tr> <% Counter = Counter + 1 RS.movenext loop %> </table>
Eagleeye jeg har desværre mistet databasen, kan du lave scriptet med en XML istedet for :-D ?. MSN: starvision@starvision.dk
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.