Need to dynamically create arrays from recordset t

Results 1 to 2 of 2

Thread: Need to dynamically create arrays from recordset t

  1. #1
    Join Date
    Dec 1969

    Default Need to dynamically create arrays from recordset t

    I want to grab certain records from a database and populate an array with it. After I have populated the array. I would like to use a For Each...Next statement to create an output that has a direct correlation with the record in the arrays.<BR><BR>EX: grab all categories out of a table in the database. Create an output that lists each category, and under each category it lists every record from another table in the database that falls under the category.<BR><BR>If there is a better solution, please advise.<BR><BR>Thanks!

  2. #2 Guest

    Default Way to go!

    So you would open a rs for the category table and use rs.getrows to put the result in an array, and close recordset. Then you would open a rs for the Items table and use getrows to put in a second array and close rs. Then loop through first array and to print categories and at each category a loop to display the items. It would look like this:<BR><BR>&#060;%<BR>cmdSQL = "Select * from Categories Order by Category"<BR>Rs.Open cmdSQL, Conn<BR>Cats = Rs.GetRows<BR>Rs.Close<BR><BR>cmdSQL = "Select * from Items Order by Category"<BR>Rs.Open cmdSQL, Conn<BR>Items = Rs.GetRows<BR>Rs.Close<BR>Set Rs=Nothing<BR>Conn.Close<BR>Set Conn=Nothing<BR><BR>&#039Assume the category is the first field in the Category and Items table, and <BR>j=0<BR>For i = 0 to Ubound(Cats,2)<BR> Response.Write Cats(0,i) &#039 Show category<BR> do while Items(0,j) = Cats(0,i)<BR>&#039 Display itme fields <BR> j=j+1<BR> loop<BR>next<BR>%&#062;

Posting Permissions

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