Click to See Complete Forum and Search --> : Filling multidimensional arrays using ADO


MonkeyBoy
10-08-2003, 10:55 AM
I have a strange problem I can't see a way around.

I have a large recordset (183 records and 89 fields). I want to do some dynamic things on a web page, as you do, but for some reason the array only fills with the last record. When you document.write the variables at various points in the while loop it looks fine, but when you try to write out the dataset again from the array, I only get the last record. 183 times!

Where is my stupid mistake!!!????

Here’s the code:

var svr; // Server object
var rst; // Recordset object

// Create a new Server and get all data.
svr = new ActiveXObject("ADOVarietyData.ADOVarietyServer");
rst = svr.DetailsForVarieties();
var arrFields = new Array();
var nRec = 0;
var x = 0;
rst.MoveFirst();
while (!rst.EOF) {
for (x = 0; x <= 89; x++){
arrFields[nRec,x] = rst.fields(x).value;
}
nRec++;
rst.MoveNext();
}
rst.close;

//LIST 1ST THREE RECORDS DATA
for (RecNo = 0; RecNo <= nRec; RecNo++){
for (nFieldNo = 0; nFieldNo <= 89; nFieldNo++){
if (RecNo <= 2){
document.write(arrFields[RecNo,nFieldNo] + "<br>");
}
}
}

Vladdy
10-08-2003, 11:15 AM
that's not the way you do 2D arrays in Javascript

MonkeyBoy
10-08-2003, 11:24 AM
I adapted the code from other code I had which worked (this combines VBScript and JavaScript). Here's a snippet:

do while not rsSpecies.eof
%>

x = <%= trim(y) %>

Insect = new Array();
GenusID = "<%= trim(rsSpecies("GenusID"))%>";
SpeciesID = "<%= trim(rsSpecies("SpeciesID"))%>";
SpeciesName = "<%= trim(rsSpecies("SpeciesName"))%>";

Insect[x,0] = GenusID;
Insect[x,1] = SpeciesID;
Insect[x,2] = SpeciesName;

That works, so why doesn't my new code. Please tell me how to fix this. Or tell me how you do do 2D arrays in Javascript coz I haven't found anything useful so far in my net searches.

MonkeyBoy
10-09-2003, 07:37 AM
Bump.

Anyone got any ideas?