[eluser]huggiebear[/eluser]
I get the following error when trying to display the results of a query (query returns a single row).
Quote:Fatal error: Cannot use object of type stdClass as array in C:\wamp\www\ci\coresystem\libraries\Loader.php(647) : eval()'d code on line 9
Here's the code in the controller:
Code:
<?php
class Newsletter extends Controller {
function index()
{
$data['title'] = 'My Database Test';
$data['query'] = $this->db->get('main_issues');
$this->load->view('display_newsletter', $data);
}
}
?>
and here's the code in the view:
Code:
<html>
<head>
<title><?=$title?></title>
</head>
<body>
<h1>Database Test</h1>
<ul>
<?php foreach($query->result() as $row):?>
<li><?=$row['issue_name']?></li>
<?php endforeach;?>
</ul>
</body>
</html>
A var_dump() of $data in the view gives this:
Code:
Array
(
[view] => display_newsletter
[vars] => Array
(
[title] => My Database Test
[query] => CI_DB_mysql_result Object
(
[conn_id] => Resource id #24
[result_id] => Resource id #25
[result_array] => Array
(
)
[result_object] => Array
(
)
[current_row] => 0
[num_rows] => 1
)
)
[return] =>
)
Does anyone have any ideas?
Regards
Huggie