Welcome Guest, Not a member yet? Register   Sign In
How can I get stdClass Object instead of an array
#2

[eluser]Aken[/eluser]
Code:
$query = $this->db->get('auction');
            
            $new_array = array();
            
            foreach($query->result() as $row)
            {                
                // Get item name from database
                $this->db->where('id', $row->items_id);
                $item_query = $this->db->get('items');

                $item = $item_query->row_array();

                // Add a stdClass object to the final array.
                $new_array[] = (object) array(
                    'id' => $row->id,
                    'min_bid' => $row->min_bid,
                    'name' => $item['name']
                );

            }
            return $new_array; // return multi-demi array

You should also learn about SQL JOIN commands, which would allow you to attach the item name to the first query, and not need to run a second query inside each loop iteration. I could've written the code for you, but where's the fun in that? Smile


Messages In This Thread
How can I get stdClass Object instead of an array - by El Forum - 05-14-2010, 06:21 PM
How can I get stdClass Object instead of an array - by El Forum - 05-14-2010, 06:45 PM
How can I get stdClass Object instead of an array - by El Forum - 05-14-2010, 07:03 PM
How can I get stdClass Object instead of an array - by El Forum - 05-14-2010, 08:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB