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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping Through Record "Categories" Based on Another Table 1

Status
Not open for further replies.
Dec 27, 2001
114
US
I'll try to draw this out the best I can.

I have two tables, discipline (reading, math, writing, etc) and the actual information table. I want to do a loop through the information table that looks all of the records, determines the dicipline and "groups" them together when it displays

Example, the discipline table showed that a discipline id (d_it for this example) of 1 was Reading; "for each" of the d_it = 1 records in the data table, write them to the screen.

Reading (d_it = 1)
Level
Target
Focus
Strategy
Resource

"next"

Then, loop through the d_it = 2, 3, 4, etc.

I originally designed these disciplines as hard coded (Math, Science, Reading, Writing, etc); however, the customer wants to be able to update the table (which also populates a combo box that users are "editing" these from) if the local government decides to add new curriculum areas.

I've tried different for each loops, while not, etc... no luck and/or I'm just not getting the code correct.

Let me know if you need more details or a better explaination... and I'll keep updating the thread as I think of things...

Regards,

David

---
David R. Longnecker
Web Developer
CCNA, MCSA, Network+, A+
Management Information Services
Wichita Public Schools, USD 259
 
... I'm not sure why this matters... it's all varchar in the database... but...
[code
if rows(2,i)=[hightlight]cstr[/highlight](rs2("disc_id")) then
[/code]

...fixed the problem... with that oddity.

---
David R. Longnecker
Web Developer
CCNA, MCSA, Network+, A+
Management Information Services
Wichita Public Schools, USD 259
 
... grr... it's the CSTR function. The one time I don't preview... I can't type. (T_T)

---
David R. Longnecker
Web Developer
CCNA, MCSA, Network+, A+
Management Information Services
Wichita Public Schools, USD 259
 
Okay... I'd like to thank my personal hero, steven290, lol...

Here is the final code. I tweaked it a bit to avoid the whole "record doesn't exist, blowing up" issue. I still need to clean up the variables and such and place comments... but the functionality is there and, so far, works quite well! I thank everyone for their time with this... I've learned a ton about how the loops work with experimenting and customizing the code and am going to have to tinker with the GetRows function... that looks a lot simplier than the "while not eof" I've always done.

Code:
<%

query = "select * from plans_Section6 where cip_id = '" & cip_id & "'"
set rs = cipconnect.execute(query)

query = "select * from plans_discipline ORDER by disc_name"
set rs2 = cipconnect.execute(query)

if not rs.eof then
	rows = rs.getrows()

do while not rs2.eof
%>
<table width="100%">
<tr><th colspan="5"><%=rs2("disc_name")%></th></tr>
<tr>
	<th width="20%" class="subheader">Level</th>
	<th width="20%" class="subheader">Target Area</th>
	<th width="20%" class="subheader">Focus Area</th>
	<th width="20%" class="subheader">Strategy</th>
	<th width="20%" class="subheader">Resources</th>
</tr>
	<% for i=lbound(rows,2) to ubound(rows,2)
		if clng(rows(2,i))=clng(rs2("disc_id")) then
		%>
		<tr>
		<td><p><%="<a href='edit_cip_section6.asp?cip_id=" & cip_id & "&strategy_id=" & rows(0,i) & "&action=delete' onclick=""javascript:return confirm('Are you sure you want to delete this strategy?')"">" & LookupLevel(rows(3,i)) & "</a>"%></p></td>
		<td><p><%=LookupTarget(rows(4,i))%></p></td>
		<td><p><%=LookupFocus(rows(5,i))%></p></td>
		<td><p><%=LookupStrat(rows(6,i))%></p></td>
		<td><p><%=rows(7,i)%></td>
		</tr>
		<%
		end if
next
	rs2.movenext
		%><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><% ' Add some spacing in...
loop

else
	response.write("<tr><td><p><strong>No strategies found...</strong></p></td></tr>")
end if

%>

Thanks a ton!

Regards,

David

---
David R. Longnecker
Web Developer
CCNA, MCSA, Network+, A+
Management Information Services
Wichita Public Schools, USD 259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top