Forum Moderators: coopster

Message Too Old, No Replies

Building an Array from a Database

         

Harvs

12:34 am on Nov 8, 2005 (gmt 0)

10+ Year Member



Hi,

Just a quick questions. I'm retrieving two fields from a database one being "id" and the other "name". I am currently using this to load the results

$i=0;
while($row = $db->fetchArray($results)) {
nameArray[$i] = $row;
$i++;

Which fetches the results by Association and gives me these results:

Array (
[0] => Array ( [id] => id1 [name] => FirstName )
[1] => Array ( [id] => id2 [name] => SecondName )
)

is there some way to modify the code so I get this result:

Array (
[id1] => FirstName
[id2] => SecondName
)

It seeem like it should be possible but I just can't seem to work it out.

Thanks in advance
-Harvs-

NomikOS

1:33 am on Nov 8, 2005 (gmt 0)

10+ Year Member



depends how you construct fetchArray()
try this:

while ($row = $db->fetchArray($results))
{
$nameArray[$row['id']] = $row['name'];
}

Harvs

2:13 am on Nov 8, 2005 (gmt 0)

10+ Year Member



Thanks NomikOS that works just they way I wanted it to now.

It seems logical now that I look at it but I just couldn't get the syntax right.

Cheers
-Harvs-

NomikOS

2:36 am on Nov 8, 2005 (gmt 0)

10+ Year Member



yeah, cheers!