It is just misplaced buddy, most of it anyway.
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") &"")
Response.Write("-----------------------------")
LastTopCat = TopCat
End If
Response.Write(RS("middlecategory"))
End If
Response.Write("</td>")
Next
Response.Write("</tr>")
RS.MoveNext
loop
End If
Response.Write("</table>")
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
it doesn't make sense. Those two should be inside the same cell. Can you take a screenshot and post it up please?
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
Not sure exactly what you want. The code works exactly how it is supposed to.
Are you trying to have each cell be different, regardless of column? If so, move this line:
RS.MoveNext
two lines up, right above the "Next" statement.
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
Then here you go:
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") & "")
Response.Write("-----------------------------")
LastTopCat = TopCat
Response.Write(RS("middlecategory"))
End If
End If
Response.Write("</td>")
RS.MoveNext
Next
Response.Write("</tr>")
loop
End If
Response.Write("</table>")
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
Okay here is the work around. And sorry, I left out the last time, that's why it looks a bit funky.
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") & "")
Response.Write("-----------------------------")
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>")
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
I left in the "or" command with no argument.
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") & "")
Response.Write("-----------------------------")
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>")
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
Okay, then this is the way I would do it if you don't mind me rewriting:
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") & "")
If MiddleCat <> "" Then
Response.Write("-----------------------------")
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>")
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
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:
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") & "")
LastTopCat = TopCat
If MiddleCat <> "" Then
Response.Write("-----------------------------")
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>")
However, your "DISTINCT" should have picked through this so there are no repetitions.
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
Try changing your SQL to this before changing the above code.
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 "
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68