Re: Bizarre array create error

From: Date: Tue, 31 Jul 2007 06:00:09 +0000
Subject: Re: Bizarre array create error
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-259868@lists.php.net to get a copy of this message
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?

« previous php.general (#259868) next »