| | |
Nested loop
Please support our ASP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
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)
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 " RS.Open SQL,Conn Cols = 3 Response.Write("<table width='570' border='1'>") If Not RS.EOF then Do Until RS.EOF Response.Write("<tr>") For i = 1 To Cols If RS.EOF then Response.Write("<td width='190'>xx") Else Response.Write("<td width='190'>") TopCat = RS("topcategory") If LastTopCat <> TopCat or Then Response.Write(RS("topcategory") & "<br>") Response.Write("-----------------------------<br>") LastTopCat = TopCat Response.Write(RS("middlecategory")) End If Response.Write("</td>") RS.MoveNext End If Next Response.Write("</tr>") loop End If Response.Write("</table>")
•
•
Join Date: Feb 2008
Posts: 174
Reputation:
Solved Threads: 3
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"
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"
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
I left in the "or" command with no argument.
ASP Syntax (Toggle Plain Text)
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 " RS.Open SQL,Conn Cols = 3 Response.Write("<table width='570' border='1'>") If Not RS.EOF then Do Until RS.EOF Response.Write("<tr>") For i = 1 To Cols If RS.EOF then Response.Write("<td width='190'>xx") Else Response.Write("<td width='190'>") TopCat = RS("topcategory") If LastTopCat <> TopCat Then Response.Write(RS("topcategory") & "<br>") Response.Write("-----------------------------<br>") LastTopCat = TopCat Response.Write(RS("middlecategory")) End If Response.Write("</td>") RS.MoveNext End If Next Response.Write("</tr>") loop End If Response.Write("</table>")
•
•
Join Date: Feb 2008
Posts: 174
Reputation:
Solved Threads: 3
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.
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.
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
Okay, then this is the way I would do it if you don't mind me rewriting:
ASP Syntax (Toggle Plain Text)
Response.Write("<table width='570' border='1'>") Do While Not RS.EOF Response.Write("<tr>") For i = 1 To 3 If Not RS.EOF Then Response.Write("<td width='190'>") TopCat = RS("topcategory") MiddleCat = RS("middlecategory") If TopCat <> "" Then Response.Write(RS("topcategory") & "<br>") If MiddleCat <> "" Then Response.Write("-----------------------------<br>") Response.Write(RS("middlecategory")) End If End If TopCat = "" MiddleCat = "" Response.Write("</td>") RS.MoveNext Else Response.Write("<td width='190'></td>") End If Next Response.Write("</tr>") Loop Response.Write("</table>")
•
•
Join Date: Feb 2008
Posts: 174
Reputation:
Solved Threads: 3
It's getting better. But there still is some repeating
Check the attach.
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)
Response.Write("<table width='570' border='1'>") Do While Not RS.EOF Response.Write("<tr>") For i = 1 To 3 If Not RS.EOF Then Response.Write("<td width='190'>") TopCat = RS("topcategory") MiddleCat = RS("middlecategory") If TopCat <> "" Then Response.Write(RS("topcategory") & "<br>") If MiddleCat <> "" Then Response.Write("-----------------------------<br>") Response.Write(RS("middlecategory")) End If End If TopCat = "" MiddleCat = "" Response.Write("</td>") RS.MoveNext Else Response.Write("<td width='190'></td>") End If Next Response.Write("</tr>") Loop Response.Write("</table>")
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
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:
However, your "DISTINCT" should have picked through this so there are no repetitions.
ASP Syntax (Toggle Plain Text)
Response.Write("<table width='570' border='1'>") Do While Not RS.EOF Response.Write("<tr>") For i = 1 To 3 If Not RS.EOF Then Response.Write("<td width='190'>") TopCat = RS("topcategory") MiddleCat = RS("middlecategory") If TopCat <> "" and TopCat <> LastTopCat Then Response.Write(RS("topcategory") & "<br>") LastTopCat = TopCat If MiddleCat <> "" Then Response.Write("-----------------------------<br>") Response.Write(RS("middlecategory")) End If End If TopCat = "" MiddleCat = "" Response.Write("</td>") RS.MoveNext Else Response.Write("<td width='190'></td>") End If Next Response.Write("</tr>") Loop Response.Write("</table>")
Last edited by SheSaidImaPregy; Feb 14th, 2008 at 4:17 pm.
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
Try changing your SQL to this before changing the above code.
ASP Syntax (Toggle Plain Text)
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 "
•
•
Join Date: Feb 2008
Posts: 174
Reputation:
Solved Threads: 3
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>
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>
![]() |
Similar Threads
- Do/While Loop help (C++)
- nested for loop problem (Java)
- Can not enter multiple data into nested while loop (C++)
- problem creating a for loop for an array (C++)
- Nested loop that runs until user enters 'q' (C++)
- QBasic Nested for loop (Legacy and Other Languages)
- need help w/for loop (C++)
Other Threads in the ASP Forum
- Previous Thread: Help: passing variable via table field different page subroutine
- Next Thread: Convert Int to string classic asp
| Thread Tools | Search this Thread |
Tag cloud for ASP
archive asp asp.net aspandmssqlserver2005 aspandmssqlserver2005connection aspconnection calendar changeable connection current database databaseconnection diagnostics dreamweaver excel fso html iis microsoft msmsql mssql2005 mssqlserver2005 mssqlserver2005andasp mssqlserverandasp opentextfile record searchbox selectoption server single specfic sqlserver sqlserverconnection toolkit web webserver windows7






