I want to show all records from database..but when i want to show records the browser show error and the error is: "
A PHP Error was encountered
Severity: Error
Message: Cannot use object of type stdClass as array
Filename: views/show_designation.php
Line Number: 53
Backtrace: "
View
<?php print_r($designation); $i=1;foreach($designation as $desig): ?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $desig['name']; ?></td> This is (LINE 53)
<td><a href="<?php echo base_url('index.php/designation/delete_designation/'.$desig[$i]->dkey);?>"><input type="button" value="Delete" class="btn btn-danger"/></a>
<td class="numeric"><a id= "<?php echo $desig[$i]->dkey; ?>" onclick="edit_designation('<?php echo $designation[$i]->dkey; ?>')" data-target="#myModal" data-toggle="modal" style="color:#ffffff;" href="#myModal"><button class="btn blue" type="button">Edit</button>
</tr>
<?php $i++;endforeach;?>
COntroller
public function get_designation()
{
$this->load->model('designation_model');
$userlist=$this->designation_model->get_alldesignation_model();
$data['designation']=$userlist;
$this->load->view('show_designation',$data);
}//edit_project
Model
public function get_alldesignation_model()
{
$query = $this->db->get('designations');
$result=$query->result();
return $result;
}
To use result of query as array say
because by default result is returned as object