Welcome Guest, Not a member yet? Register   Sign In
Trying to iterate results in controller as a non object.
#1

[eluser]Unknown[/eluser]
Newbie Help requested.

I took a CRUD framework that works great. Now I am trying to list results that come from more than one db table. I am having trouble accessing the results in the controller.

Here is my model code...

function get_all_list(){

$this->db->select('users.id, username, fullname, email, phone, company_id, name AS companyname')->from('users')->join('companies', 'users.id = companies.id', 'inner')->order_by('users.id','asc');

$sql = $this->db->get();

if($sql->num_rows() > 0){
return $sql->result();
} else {
return array(); //return empty array if no results
}

}

Here is my controller code...

$resultset = $this->userModel->get_all_list();
foreach($resultset as $row)
{
$deleteMessage = 'Do you really want to delete this record: ' . $row['username'] . ' ?';
$this->table->add_row(
++$i,
$row['id'],
anchor('user/getDetail/'.$row['id'], $row['username'], array('class'=>'simple_link')),
$row['fullname'],
$row['email'],
$row['phone'],
$row['company_id'],
$row['companyname'],
anchor('user/getDetail/'.$row['id'],'view',array('class'=>'view')).' '.
anchor('user/getUpdate/'.$row['id'],'update',array('class'=>'update')).' '.
anchor('user/delete/'.$row['id'],'delete',array('class'=>'delete','onclick'=>"return confirm('" . $deleteMessage .
"')"))
); // end add_row
}

The error I currently get is in trying to access the $row['username'].

Error is Fatal error: Cannot use object of type stdClass as array in .../ci/application/controllers/user.php on line 93


This is line 93
$deleteMessage = 'Do you really want to delete this record: ' . $row['username'] . ' ?';

I believe I am not referencing the result passed back correctly.

Thanks for the help! MC




Theme © iAndrew 2016 - Forum software by © MyBB