943,696 Members | Top Members by Rank

Ad:
  • ASP Discussion Thread
  • Marked Solved
  • Views: 9354
  • ASP RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Feb 14th, 2008
0

Re: Nested loop

Okay here is the work around. And sorry, I left out the </td> last time, that's why it looks a bit funky.
ASP Syntax (Toggle Plain Text)
  1. SQL = "SELECT DISTINCT TC.topcategory,MC.middlecategory "&_
  2. "FROM tbtopcategory TC,tbmiddlecategory MC,tbconnectcategory CC "&_
  3. "WHERE TC.topcategoryID = CC.topcategorylink "&_
  4. "AND MC.tbmiddlecategoryID = CC.middlecategorylink " &_
  5. "GROUP BY TC.topcategory "
  6. RS.Open SQL,Conn
  7.  
  8. Cols = 3
  9.  
  10. Response.Write("<table width='570' border='1'>")
  11.  
  12. If Not RS.EOF then
  13. Do Until RS.EOF
  14. Response.Write("<tr>")
  15.  
  16. For i = 1 To Cols
  17. If RS.EOF then
  18. Response.Write("<td width='190'>xx")
  19. Else
  20. Response.Write("<td width='190'>")
  21.  
  22. TopCat = RS("topcategory")
  23.  
  24. If LastTopCat <> TopCat or Then
  25. Response.Write(RS("topcategory") & "<br>")
  26. Response.Write("-----------------------------<br>")
  27. LastTopCat = TopCat
  28. Response.Write(RS("middlecategory"))
  29. End If
  30.  
  31. Response.Write("</td>")
  32. RS.MoveNext
  33. End If
  34. Next
  35.  
  36. Response.Write("</tr>")
  37. loop
  38. End If
  39.  
  40. Response.Write("</table>")
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Feb 14th, 2008
0

Re: Nested loop

There is some error, i get back in short
Reputation Points: 10
Solved Threads: 3
Junior Poster
TobbeK is offline Offline
190 posts
since Feb 2008
Feb 14th, 2008
0

Re: Nested loop

I am really grateful for all the help I can get. This is a tricky coding we are doing.

This is With the GROUP BY clause closed, so all of the middlecats can be received.

Here is the Screen

SQL = "SELECT DISTINCT TC.topcategory,MC.middlecategory "&_
"FROM tbtopcategory TC,tbmiddlecategory MC,tbconnectcategory CC "&_
"WHERE TC.topcategoryID = CC.topcategorylink "&_
"AND MC.tbmiddlecategoryID = CC.middlecategorylink " '&_
'"GROUP BY TC.topcategory ASC"
Attached Thumbnails
Click image for larger version

Name:	table_7.jpg
Views:	10
Size:	98.0 KB
ID:	5088  
Reputation Points: 10
Solved Threads: 3
Junior Poster
TobbeK is offline Offline
190 posts
since Feb 2008
Feb 14th, 2008
0

Re: Nested loop

I left in the "or" command with no argument.
ASP Syntax (Toggle Plain Text)
  1. SQL = "SELECT DISTINCT TC.topcategory,MC.middlecategory "&_
  2. "FROM tbtopcategory TC,tbmiddlecategory MC,tbconnectcategory CC "&_
  3. "WHERE TC.topcategoryID = CC.topcategorylink "&_
  4. "AND MC.tbmiddlecategoryID = CC.middlecategorylink " &_
  5. "GROUP BY TC.topcategory "
  6. RS.Open SQL,Conn
  7.  
  8. Cols = 3
  9.  
  10. Response.Write("<table width='570' border='1'>")
  11.  
  12. If Not RS.EOF then
  13. Do Until RS.EOF
  14. Response.Write("<tr>")
  15.  
  16. For i = 1 To Cols
  17. If RS.EOF then
  18. Response.Write("<td width='190'>xx")
  19. Else
  20. Response.Write("<td width='190'>")
  21.  
  22. TopCat = RS("topcategory")
  23.  
  24. If LastTopCat <> TopCat Then
  25. Response.Write(RS("topcategory") & "<br>")
  26. Response.Write("-----------------------------<br>")
  27. LastTopCat = TopCat
  28. Response.Write(RS("middlecategory"))
  29. End If
  30.  
  31. Response.Write("</td>")
  32. RS.MoveNext
  33. End If
  34. Next
  35.  
  36. Response.Write("</tr>")
  37. loop
  38. End If
  39.  
  40. Response.Write("</table>")
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Feb 14th, 2008
0

Re: Nested loop

Yes i noticed the Or argument before and take it away, but it is the same output as my last post.

Is there anyway to count the middlecategory posts for each of the topcategory, flag the last middlecategory and write a </tr> if the last post has been reached. I have tried that but without success.

What I am trying to do here is (a simple) small directory link table (like Yahoo). With Topcategory and undercategory links (URLs) Nothing fancy, even if it is trickier that first thought.
Last edited by TobbeK; Feb 14th, 2008 at 3:37 pm.
Reputation Points: 10
Solved Threads: 3
Junior Poster
TobbeK is offline Offline
190 posts
since Feb 2008
Feb 14th, 2008
1

Re: Nested loop

Okay, then this is the way I would do it if you don't mind me rewriting:
ASP Syntax (Toggle Plain Text)
  1. Response.Write("<table width='570' border='1'>")
  2.  
  3. Do While Not RS.EOF
  4. Response.Write("<tr>")
  5.  
  6. For i = 1 To 3
  7. If Not RS.EOF Then
  8. Response.Write("<td width='190'>")
  9.  
  10. TopCat = RS("topcategory")
  11. MiddleCat = RS("middlecategory")
  12.  
  13. If TopCat <> "" Then
  14. Response.Write(RS("topcategory") & "<br>")
  15.  
  16. If MiddleCat <> "" Then
  17. Response.Write("-----------------------------<br>")
  18. Response.Write(RS("middlecategory"))
  19. End If
  20. End If
  21.  
  22. TopCat = ""
  23. MiddleCat = ""
  24.  
  25. Response.Write("</td>")
  26. RS.MoveNext
  27. Else
  28. Response.Write("<td width='190'></td>")
  29. End If
  30. Next
  31.  
  32. Response.Write("</tr>")
  33. Loop
  34.  
  35. Response.Write("</table>")
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Feb 14th, 2008
0

Re: Nested loop

It's getting better. But there still is some repeating

Check the attach.

Okay, then this is the way I would do it if you don't mind me rewriting:
ASP Syntax (Toggle Plain Text)
  1. Response.Write("<table width='570' border='1'>")
  2.  
  3. Do While Not RS.EOF
  4. Response.Write("<tr>")
  5.  
  6. For i = 1 To 3
  7. If Not RS.EOF Then
  8. Response.Write("<td width='190'>")
  9.  
  10. TopCat = RS("topcategory")
  11. MiddleCat = RS("middlecategory")
  12.  
  13. If TopCat <> "" Then
  14. Response.Write(RS("topcategory") & "<br>")
  15.  
  16. If MiddleCat <> "" Then
  17. Response.Write("-----------------------------<br>")
  18. Response.Write(RS("middlecategory"))
  19. End If
  20. End If
  21.  
  22. TopCat = ""
  23. MiddleCat = ""
  24.  
  25. Response.Write("</td>")
  26. RS.MoveNext
  27. Else
  28. Response.Write("<td width='190'></td>")
  29. End If
  30. Next
  31.  
  32. Response.Write("</tr>")
  33. Loop
  34.  
  35. Response.Write("</table>")
Attached Thumbnails
Click image for larger version

Name:	table_8.jpg
Views:	15
Size:	295.7 KB
ID:	5089  
Reputation Points: 10
Solved Threads: 3
Junior Poster
TobbeK is offline Offline
190 posts
since Feb 2008
Feb 14th, 2008
0

Re: Nested loop

That's because I didn't keep the If TopCat is the same as the LastTopCat. I don't know how your DB is set up, so here's the good code:
ASP Syntax (Toggle Plain Text)
  1. Response.Write("<table width='570' border='1'>")
  2.  
  3. Do While Not RS.EOF
  4. Response.Write("<tr>")
  5.  
  6. For i = 1 To 3
  7. If Not RS.EOF Then
  8. Response.Write("<td width='190'>")
  9.  
  10. TopCat = RS("topcategory")
  11. MiddleCat = RS("middlecategory")
  12.  
  13. If TopCat <> "" and TopCat <> LastTopCat Then
  14. Response.Write(RS("topcategory") & "<br>")
  15. LastTopCat = TopCat
  16.  
  17. If MiddleCat <> "" Then
  18. Response.Write("-----------------------------<br>")
  19. Response.Write(RS("middlecategory"))
  20. End If
  21. End If
  22.  
  23. TopCat = ""
  24. MiddleCat = ""
  25.  
  26. Response.Write("</td>")
  27. RS.MoveNext
  28. Else
  29. Response.Write("<td width='190'></td>")
  30. End If
  31. Next
  32.  
  33. Response.Write("</tr>")
  34. Loop
  35.  
  36. Response.Write("</table>")
However, your "DISTINCT" should have picked through this so there are no repetitions.
Last edited by SheSaidImaPregy; Feb 14th, 2008 at 4:17 pm.
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Feb 14th, 2008
0

Re: Nested loop

Try changing your SQL to this before changing the above code.
ASP Syntax (Toggle Plain Text)
  1. SQL = "SELECT DISTINCT(TC.topcategory), MC.middlecategory "&_
  2. "FROM tbtopcategory TC,tbmiddlecategory MC,tbconnectcategory CC "&_
  3. "WHERE TC.topcategoryID = CC.topcategorylink "&_
  4. "AND MC.tbmiddlecategoryID = CC.middlecategorylink " &_
  5. "GROUP BY TC.topcategory "
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Feb 14th, 2008
0

Re: Nested loop

Nope the last one did not work (same error as two posts ago)

I cut the source of your code before the last one.

I looks good, but the topcategories is repeated with the middlecategories.

On the LEFT side you see the topcategories and on the RIGHT the middlecategories.
The topcategories should be written only once.

<table width='570' border='1'>
<tr>
<td width='190'>Bil, Båt & Motor<br>-----------------------------<br>Bilservice</td>
<td width='190'>Bil, Båt & Motor<br>-----------------------------<br>Bildelar & Biltillbehör</td>
<td width='190'>Butiker & Shopping<br>-----------------------------<br>Hälsa & Skönhet</td>
</tr>
<tr>
<td width='190'>Butiker & Shopping<br>-----------------------------<br>Bygg & Trädgård</td>
<td width='190'>Butiker & Shopping<br>-----------------------------<br>Hus, Hem & Trädgård</td>
<td width='190'>Butiker & Shopping<br>-----------------------------<br>Film, Musik & Spel</td>
</tr>
<tr>
<td width='190'>Butiker & Shopping<br>-----------------------------<br>Mobilt & Telefoni</td>
<td width='190'>Butiker & Shopping<br>-----------------------------<br>Kläder, Mode & Skor</td>
<td width='190'>Butiker & Shopping<br>-----------------------------<br>Glasögon & Kontaktlinser</td>
</tr>
<tr>
<td width='190'>Butiker & Shopping<br>-----------------------------<br>Hemelektronik & Foto</td>
<td width='190'>Butiker & Shopping<br>-----------------------------<br>Företag & Kontor</td>
<td width='190'>Data, IT & Telekommunikation<br>-----------------------------<br>Datorer & Nätverk</td>
</tr>
<tr>
<td width='190'>Data, IT & Telekommunikation<br>-----------------------------<br>Mobilt & Telefoni</td>
<td width='190'>Data, IT & Telekommunikation<br>-----------------------------<br>Internettjänster</td>
<td width='190'>Ekonomi & Juridik<br>-----------------------------<br>Advokat- & Juristbyråer</td>
</tr>
<tr>
<td width='190'>Ekonomi & Juridik<br>-----------------------------<br>Administration & Redovisning</td>
<td width='190'>Ekonomi & Juridik<br>-----------------------------<br>Bank, Finans & Egendom</td>
<td width='190'>Industri & Transport<br>-----------------------------<br>Åkeri & Transporttjänster</td>
</tr>
<tr>
<td width='190'>Marknadsföring & Media<br>-----------------------------<br>Reklam & Annons</td>
<td width='190'>Marknadsföring & Media<br>-----------------------------<br>Internetmarknadsföring</td>
<td width='190'>Marknadsföring & Media<br>-----------------------------<br>Design & Formgivning</td>
</tr>
<tr>
<td width='190'>Marknadsföring & Media<br>-----------------------------<br>PR & Kommunikation</td>
<td width='190'>Sport & Fritid<br>-----------------------------<br>Äventyr & Naturupplevelser</td>
<td width='190'>xx</td>
</tr>
</table>
Reputation Points: 10
Solved Threads: 3
Junior Poster
TobbeK is offline Offline
190 posts
since Feb 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP Forum Timeline: Help: passing variable via table field different page subroutine
Next Thread in ASP Forum Timeline: count words or characters in strings advice needed





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC