Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the right output 1

Status
Not open for further replies.

sgore

Programmer
Jul 22, 2001
30
CA
I am trying to get my output to look like the example below:
I have tried using two while loops but it only prints out the month and never the days. Can someone tell show me how to loop through this??

Month
day time location direction
day ...
day ...
day ...
Month
day ...
.
etc


first I sorted my data

mySQL="select * from practice order by month, day ascending"
my table looks like this
<table width=&quot;100%&quot; border=&quot;1&quot;>
<tr>
<td>Month</td> <----- print month
</tr>
<tr>
<td width=&quot;21%&quot;>
<div align=&quot;right&quot;>Day</div> <---- print day here
</td>
<td width=&quot;10%&quot;>
<div align=&quot;center&quot;>Time</div> <-- etc
</td>
<td width=&quot;37%&quot;>
<div align=&quot;center&quot;>Location</div> <--- etc
</td>
<td width=&quot;32%&quot;>
<div align=&quot;center&quot;>Directions</div> <--- etc
</td>
</tr>
</table>







 
Here is what I have so far. It is close but still doesn't quite work. I just need to find out how to get it to stop looping through the days more than once...

<table width=&quot;100%&quot; border=&quot;1&quot;>
<tr>
<td colspan=&quot;4&quot;>Month: <%=rstemp(&quot;g_month&quot;)%></td>
</tr>
<% previous = rstemp(&quot;g_month&quot;)
do until rstemp.eof %>
<tr>
<td colspan=&quot;4&quot;><%
if rstemp(&quot;g_month&quot;) = previous then
else %>
Month: <%=rstemp(&quot;g_month&quot;)%>
<% end if %> </td>
</tr>
<%
rstemp2.MoveFirst
do until rstemp2.eof
if (rstemp(&quot;g_month&quot;) = rstemp2(&quot;g_month&quot;)) then
%>
<tr>
<td width=&quot;34%&quot;>
<div align=&quot;right&quot;><%=rstemp2(&quot;g_day&quot;)%></div>
</td>
<td width=&quot;20%&quot;>
<div align=&quot;center&quot;><%=rstemp2(&quot;g_time&quot;)%></div>
</td>
<td width=&quot;23%&quot;>
<div align=&quot;center&quot;><%=rstemp2(&quot;location&quot;)%></div>
</td>
<td width=&quot;23%&quot;>
<div align=&quot;center&quot;>directions</div>
</td>
</tr>
<% end if
rstemp2.movenext
loop

if (rstemp(&quot;g_month&quot;) <> previous) then
previous = rstemp(&quot;g_month&quot;)
end if

rstemp.movenext
loop

%>
</table>
<%
rstemp.close
set rstemp=nothing
rstemp2.close
set rstemp2=nothing
conntemp.close
set conntemp=nothing
%>

Here is my output.

Month: 01

1 9:00 AM Dr Pepper Starcenter - Euless directions
4 12:00 AM Dr Pepper Starcenter - Euless directions
9 2:00 AM scott directions

1 9:00 AM Dr Pepper Starcenter - Euless directions
4 12:00 AM Dr Pepper Starcenter - Euless directions
9 2:00 AM Dr Pepper Starcenter - Euless directions

1 9:00 AM Dr Pepper Starcenter - Euless directions
4 12:00 AM Dr Pepper Starcenter - Euless directions
9 2:00 AM Dr Pepper Starcenter - Euless directions

Month: 02
2 2:00 PM Dr Pepper Starcenter - Euless directions
5 12:00 AM Dr Pepper Starcenter - Euless directions
7 12:00 AM Dr Pepper Starcenter - Euless directions

2 2:00 PM Dr Pepper Starcenter - Euless directions
5 12:00 AM Dr Pepper Starcenter - Euless directions
7 12:00 AM Dr Pepper Starcenter - Euless directions

2 2:00 PM Dr Pepper Starcenter - Euless directions
5 12:00 AM Dr Pepper Starcenter - Euless directions
7 12:00 AM Dr Pepper Starcenter - Euless directions

Month: 04
13 12:00 AM Dr Pepper Starcenter - Euless directions
2 12:00 AM Dr Pepper Starcenter - Euless directions

13 12:00 AM Dr Pepper Starcenter - Euless directions
2 12:00 AM Dr Pepper Starcenter - Euless directions





 
You only need one recordset to achieve this effect, but you need to keep a tab on what month you are on:

dim curMonth
curMonth = &quot;&quot;

while not rs.eof
if curMonth <> rs(&quot;month&quot;) then
response.write(&quot;<tr><td>&quot; & rs(&quot;month&quot;) & &quot;</td></tr>&quot;)
curMonth = rs(&quot;month&quot;)
end if
response.write(&quot;<tr><td>& nbsp ;& nbsp ;& nbsp ;&quot; & rs(&quot;otherInfo&quot;) & &quot;</td></tr>&quot;)
rs.movenext
wend

so that all &quot;child&quot; output will be indented (with the three non-breaking spaces that I had to break up to get it to output on this site), and the months will appear as &quot;parent&quot; nodes to them because they aren't indented.

Many reports I write use this tree like structure, and you can really slick it up with the use of a string variable holding the non-breaking spaces that you output based on what level you are at. Add a few other variables to keep up with what level you are on (following the curMonth example), and you can make your tree structure go about as deep as your screen can handle... all with one recordset, and one loop with IF control blocks inside handling the indented output. Runs very efficiently for me.

hope that helps! :)
Paul Prewett
penny.gif
penny.gif
 
Paul,

Thanks a million. That worked great. I was making this thing way to complicated.

You saved the day.... :)

Thanks Again,
Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top