Page 1 of 1

Strange problem with an array

Posted: Sat Nov 01, 2003 10:17 pm
by jumbaloid
I have written a short piece of code that returns account information from a database:

function get_acc_list()
{
if(!db_connect())
{
return false;
}

$result = mysql_query( "select acc_name, fname, lname, email, active, priv from account");

if(!$result)
{
$_SESSION['error'] = "Problem: Could not find any accounts in the databse.";
return false;
}

$acc_array = array();

for($count = 1; $row = mysql_fetch_row($result); ++$count)
{
$acc_array['$count'] = $row;
}


return $acc_array;
}

The information inserted into $acc_array is there if printed out within the for loop but is not if you print it just before return $acc_array;. this is puzzeling me becuse $acc_array is declared outside of the for scope and information put into it during the for loop should remain afterwards.

Can anyone see what i am doing wrong? if so please help.

Posted: Sat Nov 01, 2003 10:47 pm
by markl999
Change $acc_array['$count'] = $row; to $acc_array[$count] = $row;

Posted: Sat Nov 01, 2003 10:53 pm
by jumbaloid
Thanks for that, it worked straight away.