Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 30th, 2008, 08:17 AM
Registered User
 
Join Date: Jun 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Listing by date

Hi all, hope this is in the correct section.

Im working with an access database doing my webpages with asp vbscript.

I want to list event records by date and have them in sections of months
i.e:
June
30th - Monthly meeting

August
2nd - Trip of Haydock races
28th - Monthly meeting

The records in an access database are like this:
ID* - autonumber
eventDate - date/time (short date)
eventText - memo (the description that is listed next to the date)

The trouble im having is that the records have the date in short date and i'd like to take the data from the database then list the month and then the events in that month underneath.

Is there anyway of doing this at all? I hope i've explained this ok, i'm abit confused :( Any help would be much appreciated.

Thanks
Paul



 
Old June 30th, 2008, 02:10 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Let's start with the very wrong assumption you made:

You wrote "the records have the date in short date...".

No, they don't. "short date" is only the DISPLAY FORMAT used WITHIN ACCESS itself. Has NOTHING to do with what is stored in the DB. Here, read this:
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=189

So all you need to do is get the events, in date order, nothing more:

Code:
<%
SQL = "SELECT eventDate, eventText FROM events ORDER BY eventDate " _
    & " WHERE DateValue(eventDate) BETWEEN #1/1/2008# AND #12/31/2008# "
Set RS = yourAlreadyOpenConnectionObject.Execute( SQL )
...
%>
You can change the date range (the BETWEEN values) to whatever you need, of course.

And then the rest of it--grouping by months and days--you can do by following the principals of this:
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=154

Where here the MONTH is the category and the individual days in the month (along with the text, of course) are the subcategories.
 
Old June 30th, 2008, 02:33 PM
Registered User
 
Join Date: Jun 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok thanks for that, i'll have a look and give it a go.

Thanks again :)

 
Old June 30th, 2008, 02:59 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Here's a nudge in the right direction, in case you have problems with the category/subcat stuff.

Code:
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
        & "Data Source=" & Server.MapPath("...relative path do MDB file...") & ";" 

SQL = "SELECT eventDate, eventText FROM events ORDER BY eventDate " _
    & " WHERE DateValue(eventDate) BETWEEN #1/1/2008# AND #12/31/2008# "

Set RS = conn.Execute( SQL )
If RS.EOF Then
     Response.Write "No events in that date range."
     RS.Close : conn.Close
     Response.End
End If

curYear = 0

Do Until RS.EOF
    eDate = RS("eventDate")
    eText = RS("eventText")
    If curYear <> Year(eDate) Then
        curYear = Year(eDate)
        Response.Write "<span class=YEAR>" & curYear & "</span><br/>" & vbNewLine
        curMonth = 0
    End If
    If curMonth <> Month(eDate) Then
        curMonth = Month(eDate)
        Response.Write "<span class=MONTH>" & curMonth & "</span><br/>" & vbNewLine
    End If
    ' then always output the event itself
    eDay = Day(eDate)
    Select Case eDay
        Case 1, 21, 31 : suffix = "st"
        Case 2, 22     : suffix = "nd"
        Case 3, 23     : suffix = "rd"
        Case Else      : suffix = "th"
    End Select
    Response.Write "<span class=EVENT>" & eDay & suffix & " -- " & eText & "</span><br/>" & vbNewLine
    RS.MoveNext
Loop
%>
 
Old June 30th, 2008, 03:01 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Oops...minor goof...

This line
    
Code:
Response.Write "<span class=MONTH>" & curMonth & "</span><br/>" & vbNewLine
Needs to be
    
Code:
Response.Write "<span class=MONTH>" & MonthName(curMonth) & "</span><br/>" & vbNewLine

so you get the month as its name, not just its number
 
Old June 30th, 2008, 03:16 PM
Registered User
 
Join Date: Jun 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I really appreciate the help. :)

I've got the jist of what to do now, i think i just needed a nudge in the right direction! ;)

Thankyou again for the help







Similar Threads
Thread Thread Starter Forum Replies Last Post
Listing 8-10 and Listing 8-16. Asp.Net BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 1 February 6th, 2008 01:11 PM
Listing 22-6 bpdsmark BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 2 March 26th, 2006 01:29 PM
Directory Listing Bleetz Pro JSP 1 September 20th, 2003 06:25 PM
No Errata Listing tialoc JSP Basics 6 August 6th, 2003 08:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.