
Using subcategories with a 3 column table
Hi people,<BR>I've got a bunch of photos showing up in a 3 column wide table. The photos are in "subgroups" (thanks for the faq Bill!), so that I can break up my table with the headings for the different groupings.<BR><BR>It's mostly working, but what I haven't figured out yet is how to add the necessary number of empty "<td> </td>" elements at the end of each subgroup where the number of photos is not exactly divisible by 3. I'll only ever have to add either one or two, but I have wrestled with it for too long... <BR><BR>I'm pretty sure it'll be something like:<BR><BR>if i mod 3 = 0 then<BR>response.write("<td>...</tr>")<BR>elseif i mod 3 = 1 then<BR>response.write("<td>...</tr>")<BR>else<BR>end if<BR><BR>but I don't know where to put it! <BR><BR>Any thoughts? It's perfect, except for those empty columns!<BR><BR>Thanks, Mike<BR><BR>The current code<BR><BR><table border=1><BR><%<BR>getphoto = "SELECT photos.* FROM photos "_<BR>& "WHERE (photos.photogroup= '"&where&"' AND photos.display= true) "_<BR>& "ORDER by subgroup ASC "<BR>Set rs_getphoto = Conn.Execute( getphoto )<BR>dim priorsub, cursub, photoid<BR>priorsub = ""<BR>dim bg<BR>Do While Not rs_getphoto.EOF<BR>cursub = rs_getphoto("subgroup")<BR> If cursub <> priorsub Then<BR> i=0<BR> If priorsub <> "" Then<BR> response.write("<tr>")<BR> End If<BR> %><BR> <td colspan="3"><%=cursub%> </td><BR> </tr><BR> <tr><BR> <%<BR> priorsub = cursub<BR> If cursub <> rs_getphoto("subgroup") Then<BR> Response.Write "Something went badly wrong!"<BR> Response.End<BR> End If<BR> response.write(i mod 3)<BR> Else<BR> <BR> End If<BR> %><BR> <td><img src="photos/<%=rs_getphoto("id")%>_s.jpg">< ;/td><BR><%<BR>if i mod 3 = 2 then <BR>response.write("</tr>")<BR>else<BR>end if<BR>i = i+1<BR>rs_getphoto.MoveNext<BR>loop<BR>rs_getphoto .close<BR>set rs_getphoto=nothing<BR>%><BR></table><BR>

Hmmm....I *THINK* I see...
...what you are doing there.<BR><BR>You want something like this:<BR><BR><TABLE><BR><TR><B R> <TD>subgroup 1 photo</TD><BR> <TD>subgroup 1 photo</TD><BR> <TD>subgroup 1 photo</TD><BR></TR><TR><BR> <TD>subgroup 1 photo</TD><BR> <TD>subgroup 1 photo</TD><BR> <TD>blank</TD><BR></TR><TR><BR> <TD>subgroup 2 photo</TD><BR> <TD>blank</TD><BR> <TD>blank</TD><BR></TR><BR>... etc.<BR></TABLE><BR><BR>Yes?<BR><BR>Let's see...How about we rewrite this, completely?<BR><BR><%<BR>...<BR><BR>priorsub = ""<BR><BR>Do While Not rs_getphoto.EOF<BR> cursub = rs_getphoto("subgroup")<BR> If cursub <> priorsub Then<BR> priorsub = cursub<BR>%><BR> <TR><BR> <TD colspan="3"><%=cursub%></td><BR><%<BR> End If<BR> For col = 1 To 3<BR> td = "&nbsp;"<BR> If Not rs_getphoto.EOF Then <BR> If rs_getphoto("subgroup") = cursub Then<BR> td = "<img src=""photos/" & rs_getphoto("id") & "_s.jpg"">"<BR> rs_getphoto.MoveNext ' only move if we "consume" a photo<BR> End If<BR> End If<BR> Response.Write "<TD>" & td & "</TD>" & vbNewLine<BR> Next<BR> If rs_getphoto.EOF Then <BR> Response.Write "</TR>" & vbNewLine<BR> Exit For<BR> End If<BR> If cursub <> rs_getphoto("subgroup") Then<BR> Response.Write "</TR>" & vbNewLine<BR> End If<BR>Loop<BR>rs_getphoto.Close<BR>%><BR> 0;/TABLE><BR><BR>************<BR><BR>Yeah, yeah...I should probably update the FAQ to use this simpler method. Dunno why I never thought of it before. Probably because I hadn't needed to combine the category stuff with multiple columns before.<BR><BR>

RE: Hmmm....I *THINK* I see...
Hey Bill <BR><BR>Thanks  that looks much less convoluted. <BR><BR>Just to verify, I want:<BR><BR><TABLE><BR><TR><B R><TD colspan=3>Subgroup 1 heading</TD><BR></TR><BR><TR><BR><TD>subgro up 1 photo</TD><BR><TD>subgroup 1 photo</TD><BR><TD>subgroup 1 photo</TD><BR></TR><BR><TR><BR><TD colspan=3>Subgroup 2 heading</TD><BR></TR><BR><TR><BR><TD>subgro up 1 photo</TD><BR><TD>subgroup 1 photo</TD><BR><TD>blank</TD><BR><TR><BR><TD colspan=3>Subgroup 2 heading</TD><BR></TR><BR><TR><BR><TD>subgro up 2 photo</TD><BR><TD>blank</TD><BR><TD>blank</TD><BR></TR><BR>... etc.<BR></TABLE><BR>... so that prior to the actual photos for each subgroup are input, there is a row where I can write in the subgroup description...<BR><BR>I'll have to try it out later and let you know how it works (it's a personal site and I'm at work). I must say, I'm a little sad to lose the little i mod 3 thing  for my level of competency, it was pure genius ;)<BR><BR>Thanks again,<BR>Mike

RE: Hmmm....I *THINK* I see...
Are you saying that each 1 of the 3 columns is a group of items to be displayed<BR>therefor 1 group and column could have 10 items and others 1 or 2 got that group?<BR><BR>So you want equal rows in each column to match the one with the most items in it?<BR>

No...look at his example!
And mine, for that matter.<BR><BR>He just wants the *columns* to come out even. Not the rows.<BR><BR>

got it backwards
thought he wanted Number of rows inside each column to be identical.<BR>building the groups inside own columns, not in rows of 3 columns.<BR><BR>my bad.<BR>

So whats wrong?
Looks like you gave him what he needed?

I think so, too...
He didn't say it doesn't work. Just that he can't test it right now. We'll find out later, presumably.<BR><BR>

Never mind.
Either I need glasses for what i read, or<BR>I need another 1/4 brain to absorb what i read...<BR>

IYAMADORK!
Teach me to try to type code into this stupid little textarea!<BR><BR>When I looked at it "in the light" it was real obvious how wrong it was!<BR><BR>Okay...good old Notepad to the rescue:<BR><BR>**********<BR><% <BR>... <BR><BR>priorsub = "" <BR><BR>Do While Not rs_getphoto.EOF <BR> cursub = rs_getphoto("subgroup") <BR> If cursub <> priorsub Then <BR> priorsub = cursub <BR>%> <BR> <TR> <BR> <TD colspan="3"><%=cursub%></td> <BR> </TR><BR><% <BR> End If <BR> Response.Write "<TR>" & vbNewLine <BR> For col = 1 To 3 <BR> td = "&nbsp;" <BR> If Not rs_getphoto.EOF Then <BR> If rs_getphoto("subgroup") = cursub Then <BR> td = "<img src=""photos/" & rs_getphoto("id") & "_s.jpg"">" <BR> rs_getphoto.MoveNext ' only move if we "consume" a photo <BR> End If <BR> End If <BR> Response.Write "<TD>" & td & "</TD>" & vbNewLine <BR> Next <BR> Response.Write "</TR>" & vbNewLine <BR>Loop <BR>rs_getphoto.Close <BR>%> <BR></TABLE> <BR>
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

