[eluser]DaTran[/eluser]
I have the basics of passing an array of $data into the view thus turning them into objects to echo.
But im having trouble getting my array to come out like my working tutorial samples.
So my question is how can I get a stdClass Object array instead of a normal array
This is my print_r() of the two, maybe it'll give you a better understanding of my suffering.
The working
Code:
Array
(
[records] => Array
(
[0] => stdClass Object
(
[id] => 4
[name] => Claymore
[price] => 25000
)
[1] => stdClass Object
(
[id] => 7
[name] => Pink Glads
[price] => 80000
)
)
)
Non working
Code:
Array
(
[records] => Array
(
[0] => Array
(
[id] => 1
[min_bid] => 25000
[name] => Claymore
)
[1] => Array
(
[id] => 2
[min_bid] => 26000
[name] => Pink Glads
)
[2] => Array
(
[id] => 3
[min_bid] => 12000
[name] => Claymore
)
)
)
This is my controller function for both of them:
Code:
function index()
{
if($query = $this->model_auction->retreave())
{
$data['records'] = $query;
}
print_r($data);
$this->load->view('view_auction', $data);
}
and as you would expect a simple snippet of my viewing:
Code:
<?php foreach($records as $row): ?>
<tr>
<td><?php echo $row->item_name; ?></td>
<td><?php echo $row->min_bid; ?></td>
</tr>
<?php endforeach; ?>
Finally the problem the model page:
Code:
$query = $this->db->get('auction');
$new_array = array();
$i = 0; // Preset for multi-demi arrays
foreach($query->result() as $row)
{
// Set new variables into new array
$new_array[$i]['id'] = $row->id;
$new_array[$i]['min_bid'] = $row->min_bid;
// Get item name from database
$this->db->where('id', $row->items_id);
$item_query = $this->db->get('items');
$item = $item_query->row_array();
$new_array[$i]['name'] = $item['name'];
$i++; // adds 1 and gets ready for new array in multi-demi array
}
return $new_array; // return multi-demi array
Sorry for so much code, im very new so please be kind.