Welcome Guest, Not a member yet? Register   Sign In
Simply Array value error. Help Request.
#1

[eluser]nullsys[/eluser]
Hello all,
I am brand new to Codeigniter, and of course, I am having a little issue.
One which im sure is so simple to solve, its hardly worth this amount of text.

Currently, I am returning database results and storing them in $query.
I would like to access one particular value (not all) and use it.

Here is the array in $query:
Code:
print_r($query);
Quote:Array ( [0] => stdClass Object ( [id] => 1 [name] => test [owner] => demo [family] => 1 [male] => 1 [registered] => 0 [xp] => 1000 ) )

Here, for example, is what I have tried, and the corresponding error msg:
Code:
print_r($query['family'];
Quote:Message: Undefined index: family

To me, it looks like "family" should return: 1. But, obviously I've missed the trick.
Any help at all would be appreciated, apologies.
I have tried searching, but to no avail.
Thank you.
#2

[eluser]fesweb[/eluser]
It's an object, not an array. So try this:
Code:
print_r($query->family);
#3

[eluser]nullsys[/eluser]
Thank you, however it returns:

Quote:"Message: Trying to get property of non-object".

Now I am confused.
#4

[eluser]WanWizard[/eluser]
To be precise: it's an array of objects.

So it should be
Code:
print_r( $query[0]->family );

try var_dump() instead of print_r(), it will make the structure more visible.
#5

[eluser]nullsys[/eluser]
[quote author="WanWizard" date="1282182124"]To be precise: it's an array of objects.

So it should be
Code:
print_r( $query[0]->family );

try var_dump() instead of print_r(), it will make the structure more visible.[/quote]

Spot on!
Thank you both kindly.
I'll see if there are any wiki/help sections on array objects.




Theme © iAndrew 2016 - Forum software by © MyBB