Help with complex nested loops

Results 1 to 4 of 4

Thread: Help with complex nested loops

  1. #1
    shawn. Guest

    Default Help with complex nested loops

    Hi,<BR><BR>I have a large list of items that is retrieved from a database. For ease of navigation I would like to group results by their first letter. For example, Apple would in the grouping of A, Banana would go with B, etc etc. That can easily be taken care of with an Order By clause in the SQL statement. This is where things get a bit tricky, at least for me. I want to query the database and have the items in alphabetical order, but do something along the lines of write.response “A” at the beginning of the items starting with A and so on. So I guess what I’m looking for is a way to write a subcategory heading every time there is a change in the first letter of an item in the recordset. Can this be done with ASP/VBScript? Does anyone have any examples of how to do this? Thanks!<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Help with complex nested loops

    &#060;%<BR>Do While Not RS.EOF<BR>If StrAlph&#060;&#062; Left(RS("SomeField"),1) Then<BR>Response.write "&#060;tr&#062;" & vbcrlf<BR>Response.write "&#060;td&#062;" & Response.write "&#060;tr&#062;" & vbcrlf<BR>Response.write "&#060;td&#062;" & Ucase(Left(RS("SomeField"),1)) & "&#060;/td&#062;" & vbcrlf<BR>Response.write "&#060;/tr&#062;" & vbcrlf<BR>End If<BR>Response.write "&#060;tr&#062;" & vbcrlf<BR>Response.write "&#060;td&#062;" & RS("SomeField") & "&#060;/td&#062;" & vbcrlf<BR>Response.write "&#060;/tr&#062;" & vbcrlf<BR><BR>StrAlph = Left(RS("SomeField"),1)<BR><BR>RS.MoveNext<BR>Loop <BR>%&#062;<BR><BR>

  3. #3
    Nils Bilhorn Guest

    Default RE: Help with complex nested loops

    By all means can this be done with VB-scripts, and it is not complicated either.<BR><BR> set Rs = db.execute("select name,c1,c2 from t order by name")<BR> letter = " "<BR> while not RS.eof<BR> if ucase(letter) &#060;&#062; ucase(left(RS("name"),1)) then<BR> letter = left(RS("name"),1)<BR> Response.write letter<BR> end if<BR> &#039;write the rest<BR> Rs.movenext<BR> wend<BR><BR>You may want to add some embellishment, but this is the basic

  4. #4
    shawn. Guest

    Default RE: Help with complex nested loops - Thanks!

    Thanks a bunch Steve and Nils. I was off in the wrong direction, but you guys set me straight. Once again, thanks!<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