Showing max 5 messages from an database
Hi ThereI just started learning Asp last week and have been finding all sorts of scripts to use and play around with. This script is made up with a few of those (Cut and Paste). The script works fine but I wish to learn how or where I can limit the page to show only 5 messages. Please Help.
Thanks
Guzzie
PS. I can read danish but my written danish is bad (This comes for me being English :)
<%
Const adOpenKeyset = 1
Const adLockOptimistic = 3
strMode = Request.QueryString(\"mode\")
tempConn = \"PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=\" & Server.MapPath(\"nyheder.mdb\") & \";UID=admin;PWD=;\"
If Request.Form(\"Send\") <> \"\" Then
strError = \"\"
strPosted = Trim(Request.Form(\"Posted\"))
strmail = Trim(Request.Form(\"mail\"))
strNews = Trim(Request.Form(\"News\"))
If Len(strPosted) = 0 Then
strError = \"Write Your Name\"
ElseIf validateEmail(strmail) = False Then
strError = \"A Real E-mail Please\"
ElseIf Len(strNews) = 0 Then
strError = \"Message Please\"
End If
If Len(strError) = 0 Then
Set rs = Server.CreateObject(\"ADODB.RecordSet\")
strSQL = \"SELECT * FROM Nyheder WHERE (ID = 0)\"
rs.Open strSQL, tempConn, adOpenKeyset, adLockOptimistic
If (rs.BOF Or rs.EOF) Then
rs.AddNew
rs(\"Posted\") = Server.HTMLEncode(strPosted)
rs(\"mail\") = Server.HTMLEncode(strmail)
rs(\"News\") = Server.HTMLEncode(strNews)
rs(\"Dato\") = Now()
rs.Update
End If
rs.Close
Set rs = Nothing
Else
strError =\"<ul><b>\" & strError & \"</b></ul>\"
strMode = \"add\"
End If
End If
%>
<html>
<head>
<title></title>
</head>
<body>
<LINK rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\">
<table width=\"600\" align=\"center\" valign=\"top\" border=\"0\">
<tr>
<td>
<%
Select Case strMode
Case \"add\"
%>
<form method=\"POST\" action=\"guestbook.asp\">
<table width=\"100%\" align=\"left\" valign=\"top\" border=\"1\">
<tr>
<td bgcolor=\"#202020\" colspan=\"2\">POST A MESSAGE</td>
</tr>
<tr>
<td><%=strError%></td>
</tr>
<tr>
<td>Name</td><td><input type=\"text\" name=\"Posted\" size=\"40\" value=\"<%=strPosted%>\"><br><br></td>
</tr>
<tr>
<td>E-mail</td><td><input type=\"text\" name=\"mail\" size=\"40\" value=\"<%=strmail%>\"><br><br></td>
</tr>
<tr>
<td>Message</td><td><textarea rows=\"3\" name=\"News\" cols=\"40\"><%=strNews%></textarea></td>
</tr>
<tr>
<td align=\"center\" colspan=\"2\"><br><br><input type=\"submit\" value=\"Send\" name=\"Send\"> <input type=\"button\" value=\"Annuller\" name=\"Annuller\" onClick=\"java script:location.href=\'guestbook.asp\'\"><br><br></td>
</tr>
<tr>
<td><br><br><a href=\"java script:window.close()\">Close Window</a></td>
</tr>
</table>
</form>
<%
Case Else
strAddLine = \"<a href=guestbook.asp?mode=add>Post Reply</a><br><br>\"
Response.Write strAddLine
strSQL = \"SELECT * FROM Nyheder ORDER BY Dato DESC;\"
Set myConn = Server.CreateObject(\"ADODB.Connection\")
myConn.Open tempConn
Set rs = myConn.Execute(strSQL)
If Not (rs.BOF Or rs.EOF) Then
Response.Write \"<table border=1 cellpadding=5 cellspacing=1>\"
Do While Not rs.EOF
dtmDato = rs(\"Dato\")
dtmDato = FormatDateTime(dtmDato,vbLongDate) & \" time \" & FormatDateTime(dtmDato,vbLongTime)
Response.Write \"<tr><td bgcolor=#202020>\" & dtmDato & \"</td>\"
If Len(rs(\"mail\")) > 0 Then
Response.Write \"<td bgcolor=#202020 align=left> posted: <a href=mailto:\" & rs(\"mail\") & \">\" & rs(\"Posted\") & \"</a></td></tr>\"
End If
Response.Write \"<tr><td colspan=2>\" & rs(\"News\") & \"<br><br></td></tr>\"
rs.MoveNext
Loop
Response.Write \"</table>\"
Else
Response.Write \"Nobody has a message\"
End If
myConn.Close
Set myConn = Nothing
Response.Write strAddLine
End Select
%>
</tr>
</table>
</div>
</body>
</html>
<script language=\"VBScript\" runat=\"Server\">
Function validateEmail(strmail)
validateEmail = True
If Len(strmail) < 6 Then
validateEmail = False
End If
If InStr(1, strmail, \"@\", 1) < 2 Then
validateEmail = False
End If
If InStr(1, strmail, \".\", 1) = 0 Then
validateEmail = False
End If
pos = InStr(1, strmail, \"@\", 1)
If pos < 2 Then
validateEmail = False
Else
pos = InStr(pos+1, strmail, \"@\")
If pos > 0 Then
validateEmail = False
End If
End If
End Function
</script>
