Hi,
First off, it's been a long time since I visited the forum, and I'm glad to see that there are some very good changes. But the one thing that I don't think is right, is that older posts, from older forum versions, have been deleted. That's a lot of useful information for anyone trying to search for help. And obviously, it is easier to keep those posts, rather than answering the same questions again and again.
Anyways, I have a bit of a problem on an asp archive page I'm building. Currently, it displays the number of records I want to. But now, I'd like to work differently, by fortnight.
This is to be a page which contains a list of my articles. I post articles at least thrice a week. The older articles in the archive, I save as html files, and display them using plain html in the archive section. As a result, I'm taking up double the webspace for the same thing. Which is why I want to use just one asp page, and that database. Users should be able to post comments for the article, so there is a comments link at the end of every article.
If someone were to go to archive.asp, the first thing they should see, is:
Archive - view fortnightly archives
[ January 2003 ]
January 16 - January 31, 2003
January 01 - January 15, 2003
[ December 2002 ]
December 16 - December 31, 2002
December 01 - December 15, 2002
[ November 2002 ]
November 16 - November 30, 2002
November 01 - November 15, 2002
[ October 2002 ]
October 16 - October 31, 2002
October 01 - October 15, 2002
Thereby showing that there are records in the database from October 2002 to January 2003, and that the user can view fortnightly entries of any of the mentioned periods.
Once a user has clicked on a link, say October 16 - October 31, 2002, then the archive.asp page should display:
[ October 16 - October 31, 2002 ]
------------------------------------- (an hr tag)
October 16 record
------------------------------------- (an hr tag)
October 15 record
------------------------------------- (an hr tag)
October 14 record
------------------------------------- (an hr tag)
October 13 record
------------------------------------- (an hr tag)
And so on and so forth. Now, how do I do this? And what code goes on the page? My asp knowledge is kinda limited, so if you could actually post the code, it would be helpful.
Right now, I'm using this code to show records:
<%
dim cn, rs
set cn = server.createObject("ADODB.Connection")
set rs = server.CreateObject("ADODB.Recordset")
function makeDBConnection()
'set the file path to the database
dbPath="database.mdb"
err.clear
on error resume next
' connect to the database
cn="driver={Microsoft Access Driver (*.mdb)};"
cn=cn & "dbq=" & server.mappath(dbPath)
if err then
Response.Write("<h3>Error Trapped</h3> while creating DB connection<p>" & err.description)
Response.End
end if
end function
function makeRS(SQL)
'Create a recordset
on error resume next
rs.Open sql, CN
if err then
Response.Write("<p>Error Trapped<p>" & err.description & "<p>while reading from DB<p> " & SQL)
Response.End
end if
makeRS=rs
end function
%>
<% makeDBConnection() %>
<%
dim dcDates, postdate
call showHeader()
call record
call showFooter()
sub record
' show the entry
' if no entry selected show the first five records
if not request("id")="" then
sql="select * from articles where artid = " & request("id") & " order by postdate desc"
else
sql="select top 5 * from articles order by postdate desc"
end if
' select records from database
makeRS(SQL)
' while not end of records ..
do while not rs.EOF
' read the title and text
strLabel=rs("strLabel")
strText=rs("strText")
artpostid=rs("artid")
%>
<hr />
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td><%=strLabel%></td></tr>
<tr><td><br /><%=strText%><br /></td></tr>
<tr><td><br /><a href="javascript:comments(<%=artpostid%>)">comments [<script type="text/javascript" src="comments.asp?artpostid=<%=artpostid%>&count=1"></script>]</a><br /></td></tr>
</table>
<%
rs.movenext
' loop
loop
rs.close
end sub
sub showHeader
' show top of page
%>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>..my articles..</td>
</tr>
</table>
<%
end sub
sub showFooter
' show bottom of page
%>
<hr />
<%