Results 1 to 5 of 5

Thread: Array Question

  1. #1
    Join Date
    Jan 2004
    Posts
    11

    Question Unanswered: Array Question

    I have successfully selected records from a certain week from my access database.

    I would like to output the results in a special way that I can't seem to work out.

    The code below only prints the records retrieved in the array. I would like to get the results like a calender, so if the array doesn't have any records from one day of the week selected in the sql-query then it writes "no records for this day" or something. So if the array doesn't hold any records from Monday I still want it to write ("<p>Monday - No records for this day</p>").

    Hope you get my point and I hope you can help an asp-noob.

    Here's the code, I left out the sql-query since I don't have any problems with that.

    <%
    arTodo = objRs.GetRows()

    objRs.Close
    Set objRs = Nothing
    conn.Close
    Set conn = Nothing

    Dim i
    Dim dtDate, strHeader
    For i = 0 to uBound(arTodo,2)

    dtDate = arTodo(0,i) 'This is the date stored in my database
    strHeader = arTodo(1,i) 'This is the headline of topic for dtDate

    Response.Write("<p>" & WeekdayName(DatePart("w", dtDate)) & " " & dtDate & " " & strHeader & "</p>" & vbNewLine )

    Next
    Erase arTodo
    %>

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    First thing you do is make sure your sql includes an order by statement so that the record with the lowest date is the first record and make sure your sql selects from a sunday to a saturday.... then you make use of the weekday function and a nice wee loop like this....
    Code:
    <%
    arTodo = objRs.GetRows()
    
    objRs.Close
    Set objRs = Nothing
    conn.Close
    Set conn = Nothing
    
    Dim i
    Dim dtDate, strHeader
    Dim myDay
    
    if uBound(arTodo,2) = 0 then i = 8 else i = 0
    
    For myDay = 1 to 7 ' Days of the week, starting sunday, finishing Saturday
      dtDate = arTodo(0,i) 'This is the date stored in my database
      if weekday(dtDate) = myDay then
        strHeader = arTodo(1,i) 'This is the headline of topic for dtDate
        i = i +1
        if i > uBound(arTodo,2) then i = 8 ' passed end of array, no more records
      else
        strHeader = "No records for this day"
      end if
      Response.Write("<p>" & WeekdayName(myDay) & " " & dtDate & " " & strHeader & "</p>" & vbNewLine )
    Next
    Erase arTodo
    %>
    that should be pretty close I think

  3. #3
    Join Date
    Jan 2004
    Posts
    11
    Thanx for your help, but the code doesn't work

    The days are written correctly but the date doesn't change, it remains the same through the entire loop. strHeader doesn't print correctly either.

  4. #4
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Like I said, "should be pretty close", close enough to get you to the next step if you take the time to understand it. If you want more help you need to answer these questions....

    Why take it out of the recordset and put it into an array?

    With your layout (and I'm only using what you supplied here) what do you actually want it to look like?

    With the date not changing. How are you determining what your first date is?? Eg. what Sunday to start your selection from.

    Have you made sure that your query is doing as I stated in my post eg ordered and starting from Sunday?

  5. #5
    Join Date
    Jan 2004
    Posts
    11
    Sorry for the late reply, I've been away from home.

    I put the results in an array so that I can close the recordset and the connection as fast as possible. I try to do this all the time just to be as economic as possible on serverload.

    I also thought that it would be a good idea to have the results in an array and then when the recordset and the connection is closed and set to nothing I could manipulate the data the way I would like to present it.

    Anyway, I've solved the problem in another way, by using 7 different sql-questions, one for each day of the week, to get the result. I was hoping not to have to do it this way but I couldn't find any other solution.

    I wanted the code to print a calendar-like output for one week, where it prints each day for the week in question and if there are matching entrys in the database for a day of that week it prints that entry. If there aren't any matches it still prints that day with the text "No records for this day".

    Thanx for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •