Forum Moderators: coopster

Message Too Old, No Replies

Problem trying to create 2-dimensional associative array with loops

         

NooK

2:38 pm on Aug 31, 2007 (gmt 0)

10+ Year Member



I am trying to create a 2-dimensional associative array by filling it in with a for loop

I ma getting my data from a sql table and basically I want and array that gives me the data.

I try doing


while (!$rs->EOF)//Continue until reaching last row
{
for($cls = 1; $cls < $numOfColumns; $cls++)
{
$data["'".columnName[$cls]."'"]["'".$column[0]."'"] = "'".column[$cls]."'";
}
$rs->moveToNextRow();
}

Now the above is sort of abstract but all it does it create an array called data that has the name of the column as the first key, the data from the first column (And current row) as second key and it is equal to the data (From that row) of the current column.

If I print_r the array atfer it is filled I get something like


Array ( ['English'] => Array ( ['admin'] => 'Admin' ['admin_title'] => 'Admin Panel' ) ['Swedish'] => Array ( ['admin'] => 'Admin' ['admin_title'] => 'Admin panel') )

But the problem is that if I try retrieving data, for example

echo = $data['English']['admin'];

I keep getting

Notice: Undefined index: English in ..... on line 30

I am rather new to php (But with experience in programming i general) and from what I have gathered I can't find what is wrong.

UPDATE: I managed to solve it. Seems the objects I was trying to set as keys weren't quite String so I fixed it by removing the quotes (') and called the proper function to get it into a string.
Couldnt find a DELETE thread button. Sorry

Best Regards

NooK

[edited by: NooK at 2:44 pm (utc) on Aug. 31, 2007]

supermanjnk

3:26 pm on Aug 31, 2007 (gmt 0)

10+ Year Member



Is that what it actually says when you output you do print_r($data)?

if so then try

echo $data["'English'"]["'admin'"];

According to what you have typed there in the array, it looks like the single quotes are part of the array key.