Multidimensional arrays can be tricky to work with. One of the most common ways of producing a multidimensional array is by creating a recordset and then dumping the data into an array using the ASP getRows() command. This is a quick FAQ answer to explain how to work with multidimensional arrays.
' Assuming we have created a connection, executed some SQL, ' and opened a recordset named rs ' Now we can dump all of the data in rs into an array called rsArray rsArray = rs.getRows() ' An advantage of getRows() - rs object is no longer needed in memory rs.Close set rs = nothing ' If the array is a large grid of data, you identify ' the columns as (rsArray, 1) and the rows as (rsArray, 2) ' A single item in the array is located at rsArray(column, row) colStart = LBound(rsArray, 1) colEnd = UBound(rsArray, 1) rowStart = LBound(rsArray, 2) rowEnd = UBound(rsArray, 2) ' Loop through all rows of the array and display the data Response.Write("<table>" & chr(13)) For row=rowStart to rowEnd Response.Write("<tr>" & chr(13)) ' For each row we loop through every column For col=colStart to colEnd Response.Write(chr(9) & "<td>" & rsArray(col,row) & "</td>" & chr(13)) Next Response.Write("</tr>" & chr(13)) Next Response.Write("</table>" & chr(13))
The chr commands in the output lines insert tabs and carriage returns to format the source for easy viewing.
If you have any questions about multidimensional arrays or suggestions for expanding this FAQ please drop me a note!