Posted by Schraalhans Keukenmeester on 04/02/07 11:49
TKirahvi wrote:
> Why can't I create Objects in an Array within for/while loop?
>
> If I have:
>
> Code:
>
> $galleries = array();
>
> while( $db->next_record() )
> {
> $foo = $db->f('id');
> $galleries[] = new Gallery($foo);
> }
>
>
> Database query returns two id's and galleries array should then
> contain two Gallery Objects but it contains only the first one.
>
> If I do it like this, it works fine:
>
> Code:
>
> $galleries[] = new Gallery(1);
> $galleries[] = new Gallery(2);
>
>
> I have PHP 5.1.6
>
> Thanks in advance
>
What values does $db->f('id') return? Are there really two records? Is
$db's class doing what it's supposed to?
The problem does not lie in the assignment to $galleries[], that's for
sure. So the problem is elsewhere in your code, or the concept behind
it. Post more details, and test your snippet by echoing intermediate
results to screen. Perhaps there's a good clue.
Sh.
[Back to original message]
|