Click to See Complete Forum and Search --> : grouping records and displaying in a block


simflex
07-25-2003, 04:29 PM
hi everyone,
ok, this is not the typical complex questions I usually ask on this forum.

I am querying the database and displaying records returned to the .
So I have :
empid first name last name title status

Then their values will be display in an html table
using the traditional <table><tr><td></td></tr></table>
tags.
I am also using a paging mechanism since the client wants 7 records displayed per page.
So far, everything works great.
Here is my problem.
Each empid comes in multiples of 3.
In other words, looking at this example:
empid first name last name title status
1 sim maxwell programmer open
1 Martin short Comedial open
1 John MCenroe Tennis Complete

From this simple example, empId comes in multples of 3.
empid 1 (3 times), empid 2(3 times), empid 3(3times), you get the picture.
I need to put each set of empids with their associated values in a box, followed by a blank row and the the next set of 3 empids followed by blank row.
Each set of empids need to be followed with a blank row to separate them out.
Is their anyway I can get someone to help me, please.
The code I am using just jumbles all the records together and make them unreadable.
Here is a snippet of what I have so far. Perhaps someone can tell me what I am doing wrong.
This is not the entire code, just snippet
Thanks in advance.


'Build table header
With Response
.write "<table border=1 cellpadding=5 cellspacing=0>"
.write "<tr bgcolor=silver>"
.write "<td>ID Number</td>"
.write "<td>Date Of Event</td>"
.write "<td>Time Of Event</td>"
.write "<td>Operator Involved</td>"
.write "<td>Type</td>"
.write "<td>Name</td>"
.write "<td>Accident Notes</td>"
.write "<td>Call back Number</td>"
.write "<td>Date & Time Info Entered</td>"
.write "<td>Completed?</td>"
.write "</tr>"
end with


Dim Count 'We'll use this to limit the number of records displayed on a page
Dim nLastID,trackingNumber
Dim bFirstChange

nLastID = -1 ' Initialize the id comparing variable.
bFirstChange = True ' Initialize flag that checks for first change of IDs.

Count = 1
do while NOT rst.EOF AND Count <= IntPageSize
If trackingNumber <> nLastID Then ' A change in EmpID has occurred
If bFirstChange = False Then
Response.Write "<tr>"
Response.Write "<td colspan=3> *</td></tr>"
Else
bFirstChange = False
End If
Response.Write "<tr><td colspan=3>Tracking#" & rst("trackingNumber") & "<td></tr>"
nLastID = trackingNumber
End If
Response.Write "<tr>"
Response.Write "<td>" & rst("DateOfEvent") & "</td>"
Response.Write "<td>" & rst("TimeOfEvent") & "</td>"
Response.Write "<td>" & rst("staffMem") & "</td>"
%>
<td>
<% If rst("type") = "Programmer" Then
Response.Write "<font color=""#000000"">Programmer</font>"
ElseIf rst("type") = "tenn" Then
Response.Write "<font color=""#000000"">Tennis Player</font>"
Else
Response.Write "<font color=""#000000"">Comedian</font>"
End If %>
</td>
<%
Response.Write "<td>" & rst("fullname") & "</td>"
Response.Write "<td>" & rst("accidentNotes") & "</td>"
Response.Write "<td>" & rst("callbackNumber") & "</td>"
Response.Write "<td>" & rst("DateTimeLog") & "</td>"
%>
<td>
<% If rst("Completed") = 0 Then
Response.Write "<font color=""#FF0000"">No</font>"
Else
Response.Write "<font color=""#009900"">Yes</font>"
End If %>
</td>
<%
Response.write "</tr>"
count = count + 1
rst.MoveNext
loop

simflex
07-26-2003, 06:38 AM
I solved it.
Thanks amnyway for responding.

simflex
07-26-2003, 10:42 AM
Ok Dave, here you go.
The main reason the code snippet I posted here was unreadable was because I used 3 for the spacer that did not equal the total number
of columns on my table which was 10. As soon as I made that adjustment of using 10 for the spacer, most of the
problems disappeared. It became a question of moving codes around a little bit.

But anyway, I took a slightly different approach from the one you suggested.
First an id to compare variables with called nLastID, then a flag that checks for first change of IDs
called bFirstChange.
Then I looped through a record set called rst.
As soon as the last ID (nLastID) is encounted, a blank space with an asterik (*) is inserted, thereby separating the one set
of ids from subsequent ones.
Finally, I created a row that repeats the column headers thereby producing something like this:


ID #xx
col1 col2 col3
### ### ###
### ### ###
### ### ###
---------------
*
---------------
ID #xx
col1 col2 col3
### ### ###
### ### ###
### ### ###
---------------
*
---------------
ID #xx
col1 col2 col3
### ### ###
### ### ###
### ### ###

Here is the code that did it!

Dim nLastID
Dim bFirstChange

nLastID = -1 ' Initialize the id comparing variable.
bFirstChange = True ' Initialize flag that checks for first change of IDs.

Do While Not rst.EOF And Count <= IntPageSize
If trackingNumber <> nLastID Then ' A change in trackingNumber has occurred.
If bFirstChange = False Then
' Stick a blank row in the table to create space.
Response.Write "<tr><td colspan=10> *</td></tr>"
Else
bFirstChange = False
End If
' Stick a row in the table with the trackingNumber
Response.Write "<tr><td colspan=10>ID #" & rst("trackingNumber") & "<td></tr>"
' stick in a row that repeats the column headers here.
' Update the compare variable.
nLastID = trackingNumber
End If
' Display all the other fields except trackingNumber here.
Response.Write "<tr>"
Response.Write "<td>" & rst("whatever") & "</td>"
Response.Write "<td>" & rst("whatever") & "</td>"
Response.Write "<td>" & rst("whatever") & "</td>"
Response.Write "</tr>"

rst.MoveNext
Loop