Asp / Database - En smartere funktion?
Jeg har lavet et mail system. Hver gang man får en ny mail bliver der udskrevet et billede med et tal. fx. Hvis jeg har en ny mail udskrives der på min side et billede af et brev med tallet 1 på. Og hvis jeg har 2 nye mails bliver der udskrevet et billede af et brev med et 2-tal på.Måden jeg har lavet min programmering er dog langt fra effektiv, synes jeg. Det burde kunne gøres simplere vha en funktion? Problemet er, at jeg ikke ved hvordan funktionen skal formuleres.
Ku forestille mig det skulle ligne noget lignende:
-----------------------------------------------------
Dim x as integer
x = 1 to 100
if rs2("ccount") = x then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post" & ("x") & ".jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
end if
------------------------------------------------------------
Det jeg har lige nu, som fungerer, er:
---------------------------------------------------------
<%
Set Conn = Server.CreateObject("ADODB.Connection")
DSN = "DRIVER={Microsoft Access Driver (*.mdb)}; "
DSN = DSN & "DBQ=" & Server.MapPath("database.mdb")
Conn.Open DSN
sSQL="SELECT COUNT(*) as ccount from mail Where TIL = '" & Request.Querystring("UserID") & "' and læst='0'"
Set rs2 = Conn.Execute(sSQL)
strSQL = "Select * From bruger Where UserID = " & Request.Querystring("UserID")
Set rs = Conn.Execute(strSQL)
if request.querystring("UserID") >1 then
if rs2("ccount") = 1 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post1.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
if rs2("ccount") = 2 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post2.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
if rs2("ccount") = 3 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post3.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
if rs2("ccount") = 4 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post4.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
if rs2("ccount") = 5 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post5.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
if rs2("ccount") = 6 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post6.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
if rs2("ccount") = 7 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post7.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
if rs2("ccount") = 8 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post8.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
if rs2("ccount") = 9 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post9.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
if rs2("ccount") = 10 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post10.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
if rs2("ccount") = 11 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post11.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
if rs2("ccount") = 12 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post12.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
if rs2("ccount") = 13 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post13.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
if rs2("ccount") = 14 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post14.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
if rs2("ccount") = 15 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post15.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
if rs2("ccount") = 16 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post16.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
if rs2("ccount") = 17 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post17.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
if rs2("ccount") = 18 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post18.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
if rs2("ccount") = 19 then
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post19.jpg' width='32' height='18' border='0'> Ulæste beskeder</a>"
else
response.write "<a href='mail.asp?UserID=" & rs("UserID") & "'>" & "<img src='images/post/post0.jpg' width='32' height='18' border='0'> Ingen nye breve</a>"
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
else
response.write "<a href='admin.asp?UserID=" & rs("UserID") & "'>Administration</a>"
end if
response.write " - <a href='search.asp?UserID=" & request.querystring("UserID") & "'><img src='images/search.gif' border='0'> Søg</a> "
response.write " - <a href='chatten.asp?UserID=" & request.querystring("UserID") & "'><img src='images/chat.gif' border='0'> Chat</a>"
Conn.Close
Set Conn = Nothing
%>
