RSS Forums RSS
Please support our ASP advertiser: Lunarpages ASP Web Hosting
Views: 4246 | Replies: 88 | Solved
Reply
Join Date: Feb 2008
Posts: 135
Reputation: TobbeK is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
TobbeK TobbeK is offline Offline
Junior Poster

Re: Nested loop

  #51  
Feb 15th, 2008
OKIDOKI

ATTACHMENT

table_1
This is my code
Only one middlecat i viewed under the first topcat and the rest is empty

table_2
This is your code
The middlecat (Bildelar & Biltillbehör) is repeated out of bound into next topcategory cell.
The first one is correct. The number of repeated middlecategory under this specific topcategory is also correct, but only the first is showed up.
Attached Images
File Type: jpg table_1.jpg (67.5 KB, 1 views)
File Type: jpg table_2.jpg (101.3 KB, 1 views)
Reply With Quote  
Join Date: Feb 2008
Posts: 135
Reputation: TobbeK is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
TobbeK TobbeK is offline Offline
Junior Poster

Re: Nested loop

  #52  
Feb 15th, 2008
Attachment 5099Here is another approach

I have used RS.Getrows instead and put everything into an array

CHECK the attachment,

As you can see all of the topcategeries and middlecategories is in their cells properly.
The problem with this code is another, I cant break it into 3 columns.



SQL = "SELECT DISTINCT TC.topcategory,MC.middlecategory "&_
"FROM tbtopcategory TC,tbmiddlecategory MC,tbconnectcategory CC "&_
"WHERE TC.topcategoryID = CC.topcategorylink "&_
"AND MC.tbmiddlecategoryID = CC.middlecategorylink " &_
"ORDER BY TC.topcategory ASC, MC.middlecategory ASC "
RS.Open SQL,Conn

arrDB = RS.GetRows()
iStart = LBound(arrDB,1)
iStop = UBound (arrDB,2)


Response.Write("<table width='570' border='1'>")

For i = iStart to iStop

TopCat = arrDB(0, i)
If LastTopCat <> TopCat Then
Response.Write("</td><td width='190'>")
TCat = arrDB(0, i) & "<br>"
Response.write TCat
LastTopCat = TopCat
End If

Response.write arrDB(1, i) & " , "

Next

Response.Write("</tr>")
Response.Write("</table>")


RS.Close
Conn.Close
Last edited by TobbeK : Feb 15th, 2008 at 1:29 pm.
Attached Images
File Type: jpg table_6.jpg (161.8 KB, 2 views)
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 62
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Nested loop

  #53  
Feb 15th, 2008
work with me here.. the code I gave you had "MiddleCat" and "MiddelCat", which is why MiddleCat is repeating, since it is never being reset.

Just make that change, MiddelCat --> MiddleCat

Same with last nights code, many typo's lol.
Reply With Quote  
Join Date: Feb 2008
Posts: 135
Reputation: TobbeK is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
TobbeK TobbeK is offline Offline
Junior Poster

Re: Nested loop

  #54  
Feb 15th, 2008
Yepp you're right, changed the middels to middle

Still it it is only the first of each middle that shows up. Take a look at the attached screen in my last post to see what I mean by that. In top above the dotted line is the topcat, below is the middles. There is another code in that post.
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 62
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Nested loop

  #55  
Feb 15th, 2008
How many middles are there for each one. You have 7 cats, look in your DB for the middles in each one so I have the number. Then I can trully know what I am looking at.
Reply With Quote  
Join Date: Feb 2008
Posts: 135
Reputation: TobbeK is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
TobbeK TobbeK is offline Offline
Junior Poster

Re: Nested loop

  #56  
Feb 15th, 2008
Each middlecat is separated by a (,) below the dotted line in the attached table 3 posts ago.

The number is of middlecats is different for each topcategory
Last edited by TobbeK : Feb 15th, 2008 at 1:41 pm.
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 62
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Nested loop

  #57  
Feb 15th, 2008
Ok, try this:
If Not RS.EOF Then
	Response.Write("<table width=""570"" border=""1"">")

	Do While Not RS.EOF
		Response.Write("<tr>")
		i = 0
		TopCat = RS("topcategory")
		MiddleCat = RS("middlecategory")

		Do While i <> 3
			If Not RS.EOF Then
				If Not LastTopCat = TopCat Then
					Response.Write ("<td width=""190"">")
					Response.Write(RS("topcategory") & "<br />")
					Response.Write("-----------------------------")
					LastTopCat = TopCat
				End If
					
				Response.Write("<br />" & MiddleCat)

				RS.MoveNext

				If Not RS.EOF Then
					TopCat = RS("topcategory")
					MiddleCat = RS("middlecategory")
				End If

				If Not LastTopCat = TopCat or RS.EOF Then
					Response.Write("</td>")
					i = i + 1
				End If
			Else
				Response.Write("<td width=""190""></td>")
				i = i + 1
			End If
		Loop

		Response.Write("</tr>")
	Loop

	Response.Write("</table>")
End If
What was failing in the previous code was the Do While TopCat = LastTopCat

It was only seeing that hit once.

EDITED: Had to move the i = i + 1 down
Last edited by SheSaidImaPregy : Feb 15th, 2008 at 1:51 pm.
Reply With Quote  
Join Date: Feb 2008
Posts: 135
Reputation: TobbeK is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
TobbeK TobbeK is offline Offline
Junior Poster

Re: Nested loop

  #58  
Feb 15th, 2008
Same :- ) not bad but same
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 62
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Nested loop

  #59  
Feb 15th, 2008
I edited it, it was mistake of placement of I, retry it with new code.
Reply With Quote  
Join Date: Feb 2008
Posts: 135
Reputation: TobbeK is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
TobbeK TobbeK is offline Offline
Junior Poster

Re: Nested loop

  #60  
Feb 15th, 2008
Same same but good looking.
Last edited by TobbeK : Feb 15th, 2008 at 1:59 pm.
Attached Images
File Type: jpg table_5.jpg (93.6 KB, 2 views)
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:55 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC