Looking for an explanation of stdClass Object |
[eluser]caperquy[/eluser]
I am currently studying codeigniter samples. It appears that the result of MySQL requests returns something like this : Array (
[eluser]mddd[/eluser]
1. StdClass means an object that has no specific class. It is "just a basic object". Every object in php start out from a 'basic object' which is then extended with all the characteristics of the specific class that it is an instance of (like Model, Controller, etc). 2. A mysql result is simply a list of objects. Each object is one row from the database result. If you wanted to display all the names, you would do: Code: foreach ($list as $item) Code: foreach ($list as $item)
[eluser]yohanip[/eluser]
hints : if you see using a var_dump : let's break them so it would be better to see the structure.. Code: Array ([list]=> accessing them, use a simple iterator such as foreach as for the example above : Code: foreach($array_list as $item) and if you see [0]=>stdClass Object([id]=>9 [name]=Anna ... ... to get id use Code: $item->id to get name use Code: $item->name
[eluser]caperquy[/eluser]
Many thanks for these clear replies. I think that I will now manage with no problem. |
Welcome Guest, Not a member yet? Register Sign In |