You are here: Re: Objects and Arrays « PHP Programming Language « IT news, forums, messages
Re: Objects and Arrays

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.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация