Hej För att kunna göra det bör du lägga till ett nytt fält i databasen. Som anger vilken datum/tid länken skapats. Sedan jämför du den med aktuell datum/tid. Du ska he ett stort tack för hjälpen men det blev liksom ett lite fel som lyder så här: Det saknadess ett %-tecken. Försök med:Vill visa att databasen är uppdaterad
Om jag vill visa att det är en kategori som är uppdaterad i en databas med en liten bild hur ska jag då skriva det i koden? och vart lägger jag den?
<head>
<title>Länkarkiv</title>
<link rel="stylesheet" href="stil.css" type="text/css">
<script src="js/tecken.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body background="bilder/bakgrund1.gif">
<div align="center">
<table width="587" border="0">
<tr>
<td width="94"><p>
src="../../statcountex/count.asp" width=90 height=30 border=0 lowsrc="../../statcountex/icostatcountex.gif"></p></td>
<td width="366"> <div align="center">
<%PK = 4
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" &Server.MapPath("db/linkz.mdb")%>
<font color="#FFFFFF"><u>Asp-Script</u></font> </div></td>
<td width="113"> </td>
</tr>
</table>
</div>
<table width="558" height="230" border="0" align="center">
<%Set RecSet=Conn.Execute("Select * From kat Order by namn")
x=0
Do Until RecSet.EOF
If x = PK Then
Response.Write "<tr>"
x = 0
End If%>
<%Set Antal=Conn.Execute("Select Count(*) As antal from linkz Where kategori=" & RecSet("id") & " And visa=True")%>
<td width="450"><%If Kat=RecSet("id") Then%><b><%End If%>
"><%=RecSet("namn")%> (<font color="#B0DFFF"><%=Antal("antal")%> </font>script)</td>
<%Antal.Close
X=X+1
RecSet.MoveNext
Loop%>
<tr>
<td colspan="<%=PK%>"> </td>
</tr>
<tr>
<td colspan="<%=PK%>"><img src="bilder/dot2.gif"><br></td>
</tr>
<%Set ReS=Conn.Execute("Select Count(*) As Antal From linkz")
Set RS=Conn.Execute("Select Count(*) As Antal From linkz Where visa=False")%>
<tr>
<td colspan="<%=PK%>">
Totalt finns det<font color="#66CCFF"> <b><%=ReS("Antal")%></b></font> script inlagda! </td>
</tr>
<tr>
<td colspan="<%=PK%>"><img src="bilder/dot2.gif"><br></td>
</tr>
<%RS.Close
If Request.QueryString("kat") <> "" Then
Set RecSet = Server.CreateObject("ADODB.Recordset")
Const lips1 = 10
Sidan = Request.QueryString("sida")
Kat = Request.QueryString("kat")
If Sidan = "" then
sida = 1
Else
sida = Sidan
End If
With RecSet
.CursorLocation = 3
.CacheSize = lips1
End With
SQL = "SELECT * FROM linkz Where kategori=" & Kat & " And visa=True ORDER by id desc"
RecSet.Open SQL, Conn
If RecSet.EOF Then%>
<tr>
<td width="450" valign="top" colspan="<%=PK%>"><font size="1">Inga
script i denna kategori ännu!</font></td>
</tr>
<%Else
With RecSet
.MoveFirst
.PageSize = lips1
.AbsolutePage = sida
End With
Sidor = RecSet.PageCount
x = 0
Do While Not RecSet.EOF And x < RecSet.PageSize%>
<td colspan="4"> <table width="531" border="0">
<tr>
<td width="148"><b><font color="#66CCFF" size="1"><%=RecSet("namn")%></font></b></td>
<td width="238"><b><font color="#FFFFFF" size="1"><%=RecSet("info")%></font></b></td>
<td width="70"><font color="#66CCFF" size="1">Antal klick: </font><font color="#66CCFF"><%=RecSet("hitz")%></font></td>
<td width="63">"></td>
</tr>
</table></td>
<tr>
<%x=x+1
RecSet.MoveNext
Loop
RecSet.Close%>
<tr>
<td width="450" valign="top" colspan="<%=PK%>"><img src="bilder/dot2.gif"></td>
</tr>
<tr>
<td valign="top" colspan="<%=PK%>">
<%If Sidor <> 1 Then
For Sid = 1 To Sidor
If (Int(Sid)) = (Int(sida)) Then%><b><%=Sid%></b><%Else%> &sida=<%=Sid%>"><%=Sid%> <%End If
Next%>
<%End If
End If
End If
If Request.QueryString("do")= "ut" Then
Set RecSet=Conn.Execute("SELECT * From linkz WHERE id=" & Request.Querystring("id"))
Conn.Execute("UPDATE linkz SET hitz=hitz+1 WHERE ID=" & Request.Querystring("id"))
Response.Redirect RecSet("link")
End If%>
</td>
</tr>
</table>
<%If Request.QueryString("do") = "add" Then%>
<table border="0" valign="top" width="400" align="center">
<form name="adda" method="post" action="linkz.asp?do=adda" onSubmit="return addlink()">
<tr>
<td><b>Lägg till ditt script - Tillbaka - Logga
ut</b></td>
</tr>
<tr>
<td><img src="bilder/dot2.gif"><br></td>
</tr>
<tr>
<td><b>Scriptets URL:</b><br><input type="text" name="link" size="60"></td>
</tr>
<tr>
<td><b>Scriptets namn:</b><br><input type="text" name="namn" size="60" maxlength="70"></td>
</tr>
<tr>
<td><b>Filinfo:</b><br><input type="text" name="info" size="60" maxlength="200"></td>
</tr>
<tr>
<td><select name="kategori">
<option value=""><--Välj kategori-->
<%Set RS = Server.CreateObject("ADODB.Recordset")
Set RS=Conn.Execute("Select * From kat Order By namn")
Do Until RS.EOF
Response.Write Space(10) & "<option value=" & chr(34) & RS("id") & chr(34) & ">" & RS("namn") & vbCrLf
RS.MoveNext
Loop
RS.Close
Set RS = Nothing%>
</select>
</td>
</tr>
<tr>
<td><img src="bilder/dot2.gif"><br></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Lägg till"></td>
</tr>
</form>
</table>
<%End If
If Request.QueryString("do")= "adda" Then
Link = Request.Form("link")
If Link <> "" Then
If Left(Link,7) = "" Then
Link = Link
Else
Link = "" & Link
End If
End If
Namn = Request.Form("namn")
Kategori = Request.Form("kategori")
Conn.execute("Insert Into linkz(link,namn,kategori) Values('" & Link & "','" & Namn & "'," & Kategori & ")")
Response.Redirect "linkz.asp"
End If%><p>
</body>
</html>Sv: Vill visa att databasen är uppdaterad
Har skrivit om din kod för att göra den mer effektiv.
<%
Dim Conn
Dim Antal
Dim RecSet
Dim x
Dim Kat
Dim Bold
Dim strKategori
Const PK = 4
Const lips1 = 10
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("db/linkz.mdb")
Set RecSet = Server.CreateObject("ADODB.Recordset")
If Request.QueryString("do") = "ut" Then
Conn.Execute "UPDATE linkz SET hitz = hitz+1 WHERE ID=" & Request.Querystring("id")
RecSet.Open "SELECT link FROM linkz WHERE id=" & Request.Querystring("id"), Conn
Response.Redirect RecSet("link")
RecSet.Close
Else
%>
<html>
<head>
<title>Länkarkiv</title>
<link rel="stylesheet" href="stil.css" type="text/css">
<script src="js/tecken.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body background="bilder/bakgrund1.gif">
<div align="center">
<table width="587" border="0">
<tr>
<td width="94"><p> </p></td>
<td width="366"> <div align="center"><font color="#FFFFFF"><u>Asp-Script</u></font></div></td>
<td width="113"> </td>
</tr>
</table>
</div>
<table width="558" height="230" border="0" align="center">
<tr>
If Request.QueryString("do") = "ut" Then
Link = Request.Form("link")
If Len(Link)> 0 Then
If Left(Link,7) = "http://" Then
Link = Link
Else
Link = "http://" & Link
End If
End If
Namn = Request.Form("namn")
If IsNumeric(Request.Form("kategori")) Then
Kategori = Request.Form("kategori")
Else
Kategori = "Null"
End If
Conn.execute "INSERT INTO linkz (link, namn, kategori) VALUES ('" & Replace(Link, "'", "''") & "','" & Replace(Namn, "'", "''") & "'," & Kategori & ")")
End If
RecSet.Open "SELECT *, (SELECT Count(*) FROM linkz WHERE kategori=kat.id And linkz.visa=True) AS Antal FROM kat ORDER BY namn")
x = 0
Kat = Request.QueryString("kat")
Do Until RecSet.EOF
If x >= PK Then
Response.Write "</tr><tr>"
x = 0
End If
Bold = (Kat = RecSet("id"))
%>
<td width="450"><%If Bold Then Response.Write "<B>"%>
"><%=RecSet("namn")%> (<font color="#B0DFFF"><%=RecSet("Antal")%></font> script)<%If Bold Then Response.Write "</B>"%></td>
<%
strKategori = strKategori & " <option value=""" RS("id") & """>" & RecSet("namn") & "</option>" & vbCrLf
X = X + 1
RecSet.MoveNext
Loop
RecSet.Close
RecSet.Open "SELECT Count(*) AS Antal, Sum(visa) AS AntalVisas FROM linkz", Conn
%>
</tr>
<tr>
<td colspan="<%=PK%>"> </td></tr>
<tr>
<td colspan="<%=PK%>"><img src="bilder/dot2.gif"><br></td></tr>
<tr>
<td colspan="<%=PK%>">Totalt finns det<font color="#66CCFF"> <%=ReS("Antal")%></font> script inlagda! </td></tr>
<tr>
<td colspan="<%=PK%>"><img src="bilder/dot2.gif"><br></td></tr>
<%
RecSet.Close
If Request.QueryString("kat") <> "" Then
Sidan = Request.QueryString("sida")
If Sidan = "" then
sida = 1
Else
sida = Sidan
End If
SQL = "SELECT * FROM linkz WHERE kategori=" & Kat & " And visa=True ORDER BY id DESC"
RecSet.PageSize = lips1
RecSet.CacheSize = lips1
RecSet.CursorLocation = 3
RecSet.Open SQL, Conn
If RecSet.EOF Then
%>
<tr>
<td width="450" valign="top" colspan="<%=PK%>"><font size="1">Inga script i denna kategori ännu!</font></td></tr>
<%
Else
x = 1
Sidor = RecSet.PageCount
RecSet.AbsolutePage = sida
Do Until RecSet.EOF Or x > lips1
%>
<tr>
<td colspan="4">
<table width="531" border="0">
<tr>
<td width="148"><font color="#66CCFF" size="1"><%=RecSet("namn")%></font></td>
<td width="238"><font color="#FFFFFF" size="1"><%=RecSet("info")%></font></td>
<td width="70"><font color="#66CCFF" size="1">Antal klick: </font><font color="#66CCFF"><%=RecSet("hitz")%></font></td>
<td width="63">"></td>
</tr>
</table></td><tr>
<%
x = x + 1
RecSet.MoveNext
Loop
%>
<tr>
<td width="450" valign="top" colspan="<%=PK%>"><img src="bilder/dot2.gif"></td></tr>
<tr>
<td valign="top" colspan="<%=PK%>">
<%
If Sidor <> 1 Then
For Sid = 1 To Sidor
If (Int(Sid)) = (Int(sida)) Then
%> <B><%=Sid%></B><%
Else
%> &sida=<%=Sid%>"><%=Sid%> <%
End If
Next
End If
End If
RecSet.Close
End If
%>
</td></tr>
</table>
<%
'Varför inte kunna alltid kunna lägga till?
' Select Case Request.QueryString("do")
' Case "add" Then
%>
<form name="adda" method="post" action="linkz.asp?do=adda" onSubmit="return addlink()">
<table border="0" valign="top" width="400" align="center">
<tr>
<td>Lägg till ditt script - Tillbaka - Logga ut</td></tr>
<tr>
<td><img src="bilder/dot2.gif"><br></td></tr>
<tr>
<td>Scriptets URL:<br><input type="text" name="link" size="60"></td></tr>
<tr>
<td>Scriptets namn:<br><input type="text" name="namn" size="60" maxlength="70"></td></tr>
<tr>
<td>Filinfo:<br><input type="text" name="info" size="60" maxlength="200"></td></tr>
<tr>
<td>
<select name="kategori">
<option value=""><--Välj kategori--></option>
<%=strKattegorier%>
</select>
</td></tr>
<tr>
<td><img src="bilder/dot2.gif"><br></td></tr>
<tr>
<td><input type="submit" name="Submit" value="Lägg till"></td></tr>
</table>
</form>
<%
' End Select
%>
</body>
</html>
<%
End If
Set RecSet = Nothing
Conn.Close
Set Conn = Nothing
%>Sv: Vill visa att databasen är uppdaterad
Feltyp:
Kompileringsfel i Microsoft VBScript (0x800A0401)
Slut på programsats förväntas.
/portal/script/TMP7yu9357g11.asp, line 78, column 55
strKategori = strKategori & " <option value=""" RS("id") & """>" & RecSet("namn") & "</option>" & vbCrLf
Vad nu detta kan vara.Sv: Vill visa att databasen är uppdaterad
strKategori = strKategori & " <option value=""" & RS("id") & """>" & RecSet("namn") & "</option>" & vbCrLf