Re: Bizarre array create error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, July 29, 2007 5:49 pm, Ken Tozier wrote:
> I'm trying to assign two fields of an object returned from a MySQL
> query and have stumbled upon the most bizarre PHP bug where I can't
> create two arrays in succession.
>
> Here's the MySQL query with two dummy fields to be filled in later
>
> select *, 0 as dummy_1, 0 as dummy_2 from table
>
> Here's how I'm grabbing the query results
>
> $result			= array();
> while ($row = mysql_fetch_object($query_result))
> {
> 	$result[]	= $row;
> }
>
> Once that's done, I try to set two of the rows to arrays like this
>
> $result-> dummy_1	= array(1, 2, 3, 4);
> $result-> dummy_2	= array('a', 'b', 'c', 'd');

$result is an array and you are treating it like an object...

While this is supposed to work, I think, it's pretty confusing to this
naive reader...

$result['dummy_1'] = array(1, 2, 3, 4);

would make more sense...

And you do realize that your actual objects are ELEMENTS of the array
$result, not $result itself...

So maybe you want something more like:

$row1 = $result[0];
$row1->dummy_1 = array(1, 2, 3, 4);

That said, you're altering an Object that MySQL returned, and I've got
NO IDEA what kind of an object that is, or what you're allowed to cram
into its variables...

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux