Reply to Re: Objects and Arrays

Your name:

Reply:


Posted by TKirahvi on 04/02/07 12:48

> 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.
>

If I echo($db-f('id')); within while loop, it echoes correct id
numbers (in this case 1 and 2), as so:

while( $db->next_record() )
{
$foo = $db->f('id');
echo($foo);
}

output: 1 2

But if I create Gallery Objects within the loop, I guess only first
one is created properly:

while( $db->next_record() )
{
$foo = $db->f('id');
gallery = new Gallery($foo);
echo($gallery->id);
}

output: 1

So it seems Arrays has nothing to do with this. I wonder if Gallery
Object is missing something crucial, I'm not that familiar with PHP's
Objects. My Gallery Object is:

class Gallery
{
var $id;
var $name;
var $description;
var $owner;
var $authority;
var $date;

function __construct($id)
{
global $db;

$select = 'SELECT * FROM gallery WHERE id = '.$id;
$result = $db->query( $select );

if ( !$result) {
echo( 'Query failed');
}
else
{
$db->next_record();
$this->id = $db->f("id");
$this->name = $db->f("name");
$this->description = $db->f("description");
$this->owner = $db->f("owner");
$this->authority = $db->f("authority");
$this->date = $db->f("date");
}
}

function __get($v)
{
return $this->$v;
}
}

[Back to original 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

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