Re: [PHP] Bizarre array create error
- From: ceo@xxxxxxxxx ("Richard Lynch")
- Date: Tue, 31 Jul 2007 01:00:09 -0500 (CDT)
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?
.
- Follow-Ups:
- Re: [PHP] Bizarre array create error
- From: Ken Tozier
- Re: [PHP] Bizarre array create error
- References:
- Bizarre array create error
- From: Ken Tozier
- Bizarre array create error
- Prev by Date: Re: [PHP] Wordpress Theme Switcher plugin redirect modification
- Next by Date: Re: [PHP] PHP Rating system
- Previous by thread: Re: [PHP] Bizarre array create error
- Next by thread: Re: [PHP] Bizarre array create error
- Index(es):
Relevant Pages
|