loop recordset

Results 1 to 3 of 3

Thread: loop recordset

  1. #1
    Join Date
    Dec 1969

    Default loop recordset

    Hi,<BR>Im still learning so Im not sure if this is even possible. I have two tables in MS Access. One table is called Category the other is Sub Category. I would like to display the Category and underneath display the Sub Category(s) that are linked to the Category, then move on to the next Category/SubCategory. I am unable to loop the Category and then loop the sub category and display the results in the correct order.<BR>I find loops confusing still, im trying to teach myself, any pointers or tips on this one would be helpful.<BR>-Kaotik

  2. #2
    Join Date
    Dec 1969

    Default Data Shaping

    see www.4guysfromrolla.com for a good article, or a slightly less detailed one on my site, below<BR><BR>j<BR>http://rtfm.atrax.co.uk/

  3. #3
    Join Date
    Dec 1969

    Default possibly..

    While i agree with atrax that data-shaping is probably the most technical astute way to go, that doesn&#039;t always mean it&#039;s the best solution.<BR><BR>I&#039;d possibly consider joining the two tables, ordering by the category (and then subcategory if you wanted to), and then loop through that one recordset.<BR><BR>if for example your tables were<BR><BR>Category<BR><BR>id name<BR>----------<BR>1 a<BR>2 b<BR>3 c<BR><BR>Sub Category<BR><BR>id FID name<BR>-------------<BR>1 2 z<BR>2 2 y<BR>3 1 x<BR>4 3 s<BR><BR>etc<BR><BR>i&#039;d use<BR><BR>select<BR> a.name, b.name<BR>from<BR> Categories a<BR> inner join<BR> Sub Categories b<BR> on<BR> a.id=b.fid<BR>order by<BR> a.name --,b.name --(if you want)<BR><BR><BR>then, after bringing this into asp as a recordset, (i&#039;d usually use getrows to put it in an array...)<BR><BR>arr=rs.getRows<BR><BR>for i = 0 to uBound(arr,2)<BR><BR> strCategoryNew=arr(0,i)<BR> <BR> if strCategoryNew=strCategoryOld then<BR> &#039;display subcategory<BR> &#039;response.write arr(1,i)<BR> else<BR> &#039;display subcategory<BR> &#039;response.write strCategoryNew<BR> end if<BR><BR> strCategoryOld=strCategoryNew<BR><BR>next<BR><BR>o r something like that.<BR><BR><BR>cp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts