Re: [PHP] Bizarre array create error



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



Relevant Pages

  • Re: XML performance extremely slow for no obvious reason
    ... on optimizing XQuery in SQL Server 2005. ... doesn't "have arrays," it sort of does, if you use a string as an array. ... it looks like XML is probably our best bet in this situation. ... I guess it's not XML as such that's the problem, just the query optimizer ...
    (microsoft.public.sqlserver.xml)
  • Re: PHP/MySQL warnings about results
    ... Getting the result arrays is easy, via mysql_fetch_array, and ... when the query in question is an INSERT, ... These queries do not return a result resource. ...
    (comp.lang.php)
  • Re: [PHP] Bizarre array create error
    ... query and have stumbled upon the most bizarre PHP bug where I can't ... Here's the MySQL query with two dummy fields to be filled in later ... I try to set two of the rows to arrays like this ...
    (php.general)
  • Constructing a search query
    ... I am doing a compound lookup by deriving person_id values for a query ... I have the id values from the lookup tables in separate arrays. ... each of which has criteria a person may search on ...
    (alt.php)
  • Re: PHP/MySQL warnings about results
    ... Getting the result arrays is easy, via mysql_fetch_array, and ... when the query in question is an INSERT, ... These queries do not return a result resource. ... for UPDATE, DELETE, etc. mysql_query returns TRUE on success and FALSE on error. ...
    (comp.lang.php)