Click to See Complete Forum and Search --> : How can I restructure this array, the default one from GetRow()


decibel
07-06-2010, 12:46 PM
hi, i'm new to asp, long time php dev, i have this code which is giving me an array from a sql query, but I need to restructure my 'records' array like the sample array below:


'objDB already created

Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "SELECT * FROM games", objDB

'Now, read the Recordset into a 2d array
Dim records
records = objRS.GetRows()


this is what i get:

Array
(
[0] => Array
(
[0] => 1
[1] => 2
)
[1] => Array
(
[0] => Bill Wall
[1] => Jill Hall
)

[2] => Array
(
[0] => 1975-01-09
[1] => 1974-04-23
)
)


this is how i need the array to be structured:

Array
(
[0] => Array
(
[0] => 1
[1] => Bill Wall
[2] => 1975-01-09
)
[1] => Array
(
[0] => 2
[1] => Jill Hall
[2] => 1974-04-23
)
)


Any help would be greatly appreciated, thanks.

yamaharuss
07-06-2010, 03:59 PM
You're dealing with a multidimensional array..
simply:

for i = 0 to Ubound(records,2)

num = records(0,i)
name = records(1,i)
date = records(2,i)

next