Welcome to WebmasterWorld Guest from 18.210.22.132

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Building an Array from a Database

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

Junior Member

10+ Year Member

joined:Oct 7, 2004
posts:89
votes: 0


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-

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

Junior Member

10+ Year Member

joined:Apr 22, 2005
posts:185
votes: 0


depends how you construct fetchArray()
try this:

while ($row = $db->fetchArray($results))
{
$nameArray[$row['id']] = $row['name'];
}
2:13 am on Nov 8, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 7, 2004
posts:89
votes: 0


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-

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

Junior Member

10+ Year Member

joined:Apr 22, 2005
posts:185
votes: 0


yeah, cheers!