PDA

View Full Version : Recordset loop


silverskymedia
05-18-2006, 08:47 PM
Hello, I'm having a bit of issues. I'm running a query and then outputing it with the date and title. That part I have working. But sometimes there are more than one item per date and I would like to only list the date once instead of on each record. Here's an example:

05/01/06

-Todays News

04/27/06

-CEO Announcements
-Today's Schedule

04/26/06

- May is Fitness Month

Any help would be appreciated. Thanks.

mehere
05-19-2006, 01:09 AM
put an if/then statement in. something like this:

do while not rs.EOF
if prevDate <> rs("curDate") then
response.Write("<br />" & rs("curDate") & "<br />")
end if
response.Write("- " & rs("strTitle") & "<br />")
prevDate = rs("curDate")
rs.MoveNext
loop

ghell
05-20-2006, 11:15 PM
Yup thats preetty much it, just check for changes' pump results into array and close the recordset and connection.
rs = objConn.Execute("select title, dateposted from news order by dateposted desc")
If NOT rs.EOF Then arrRows = rs.GetRows()
Set rs = Nothing
objConn.Close
Set objConn = Nothing

strCurrentDate = ""
If IsArray(arrRows) Then
For iRecord = LBound(arrRows, 2) To UBound(arrRows, 2)
' If the current date is out of date, change it and print the new one.
If arrRows(1, iRecord) <> strCurrentDate Then
strCurrentDate = arrRows(1, iRecord)
Response.Write "<h2>" & strCurrentDate & "</h2>"
End If

' Display the headline
Response.Write arrRows(0, iRecord) & "<br />"
Next
Else
Response.Write "No news items found."
End Ifsame effect, better code (performance wise, obviously its harder to see whats going on etc)