Avatar billede mightythor Nybegynder
20. februar 2003 - 03:45 Der er 3 kommentarer

Problemer med random og cache

Har følgende kode der gerne skulle kunne generere en ny side hver gang jeg refresher siden.... Det virker bare ikke. Er der nogen der kan fortælle mig hvorfor?

Siden kan testes her:

http://www.autonorden-it.dk/kort.asp

og her er selve koden:

<%
response.buffer=true
response.expires=-1
response.expiresabsolute= now() - 100
response.addheader "pragma", "no-cache"
response.addheader "cache-control", "private"
response.CacheControl = "no-cache"
%>

<html>
<head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-store">
<meta http-equiv="expires" content="fri, jun 12 1981 08:20:00 gmt">
<title></title>
<style>
td { font-size: 10 px }
</style>
</head>
<body>
<font face=arial>
<center>

<%
set conn = server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)}; dbq=" & server.mappath("data.mdb")
sqlstmt = "Select k1 from hands order by rnd(id)"
sqlstmt1 = "Select k2 from hands order by rnd(id)"
sqlstmt2 = "Select k3 from hands order by rnd(id)"
sqlstmt3 = "Select k4 from hands order by rnd(id)"
sqlstmt4 = "Select k5 from hands order by rnd(id)"
sqlstmt5 = "Select k6 from hands order by rnd(id)"
conn.Execute (sqlstmt)
conn.Execute (sqlstmt1)
conn.Execute (sqlstmt2)
conn.Execute (sqlstmt3)
conn.Execute (sqlstmt4)
conn.Execute (sqlstmt5)
set rs = conn.execute(sqlstmt)
set rs1 = conn.execute(sqlstmt1)
set rs2 = conn.execute(sqlstmt2)
set rs3 = conn.execute(sqlstmt3)
set rs4 = conn.execute(sqlstmt4)
set rs5 = conn.execute(sqlstmt5)
a = 1
b = 1
c = 1
d = 1
e = 1
f = 1
%>

<table width=720 cellpadding=2 cellspacing=0 border=1 bordercolor=black>
<tr>
<td colspan=3 width=120>&nbsp;</td>
<td colspan=3 width=120>&nbsp;</td>
<td colspan=3 width=120>&nbsp;</td>
<td colspan=3 width=120>&nbsp;</td>
<td colspan=3 width=120>&nbsp;</td>
<td colspan=3 width=120>&nbsp;</td>
</tr>

<%
do while not rs.eof
do while not rs1.eof
do while not rs2.eof
do while not rs3.eof
do while not rs4.eof
do while not rs5.eof
%>

<tr>
<td><%=rs("k1")%></td>
<td>&nbsp;</td>

<%
a = a + 1
response.write "<td>" & a & "</td>"
%>

<td><%=rs1("k2")%></td>
<td>&nbsp;</td>

<%
b = b + 1
response.write "<td>" & b & "</td>"
%>

<td><%=rs2("k3")%></td>
<td>&nbsp;</td>

<%
c = c + 1
response.write "<td>" & c & "</td>"
%>

<td><%=rs3("k4")%></td>
<td>&nbsp;</td>

<%
d = d + 1
response.write "<td>" & d & "</td>"
%>

<td><%=rs4("k5")%></td>
<td>&nbsp;</td>

<%
e = e + 1
response.write "<td>" & e & "</td>"
%>

<td><%=rs5("k6")%></td>
<td>&nbsp;</td>

<%
f = f + 1
response.write "<td>" & f & "</td>"
%>
</tr>

<%
rs.movenext
rs1.movenext
rs2.movenext
rs3.movenext
rs4.movenext
rs5.movenext
loop
loop
loop
loop
loop
loop
rs.close
rs1.close
rs2.close
rs3.close
rs4.close
rs5.close
conn.close
set conn = nothing
set sqlstmt = nothing
set sqlstmt1 = nothing
set sqlstmt2 = nothing
set sqlstmt3 = nothing
set sqlstmt4 = nothing
set sqlstmt5 = nothing
%>

</table>
<br>
<table width=720 cellpadding=2 cellspacing=0 border=1 bordercolor=black>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<tr>
<td>&nbsp;<br><br><br><br><br></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;<br><br><br><br><br></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;<br><br><br><br><br></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;<br><br><br><br><br></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;<br><br><br><br><br></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;<br><br><br><br><br></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;<br><br><br><br><br></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;<br><br><br><br><br></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;<br><br><br><br><br></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;<br><br><br><br><br></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;<br><br><br><br><br></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<br><br>
<a href="kort.asp">link her</a>
</center>
</font>
</body>
<head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-store">
<meta http-equiv="expires" content="fri, jun 12 1981 08:20:00 gmt">
</head>
</html>
Avatar billede dk_akj Nybegynder
20. februar 2003 - 07:23 #1
Hmm du skriver problemmer med random i overskriften men bruger da ingen for for random.

Så længe data i din DB ikke ændres vil den jo vise den samme side.

For at teste om siden gemmes i cache kunne du jo lave en response.write now() og se om det der bliver udskrevet ændres.

//akj
Avatar billede longshanks Nybegynder
20. februar 2003 - 08:37 #2
Prøv at skrive
Randomize
over de steder du bruger rnd()
Avatar billede longshanks Nybegynder
20. februar 2003 - 08:41 #3
Jeg går ud fra du vil have et tilfældigt udtrk fra databasen i form af et id, hvis du kender max/min id kan du i hvertfald generere random tal indenfor det interval med:

dim randomNumber
randomize
randomNumber = int(rnd()*100)+1

'her vil der kun genereres tal fra 1-100
Avatar billede Ny bruger Nybegynder

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.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester