尝试从codeigniter中的不同表中获取部门名称

Model: Here is my Model i want to get record from department against department id.

<?php
class Functions extends CI_Model{
    function getName($table,$column,$id){
        $this->db->select($column)->from($table)->where('id',$id);
        $query = $this->db->get();
        return $query->result_array();
    }
}
?>

View:

  33) <td><kbd><?php echo $rows['id'];?></kbd></td>
  34) <td><?php echo $rows['doctor_name'];?></td>
  35) <td><?php echo $this->functions->getName('mansoora_department','department_name',$rows['doctor_department_id']);?></td>
  36) <td><?php echo $rows['doctor_nic'];?></td>

Error:

A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: doctor/index.php

Line Number: 35

Since your method returns an Array. As clearly stated in your codes. Treat it as such:

return $query->result_array(); // an array. duh! result array :)

Either put it in another loop

<td>
    <?php 
    $names = $this->functions->getName('mansoora_department','department_name',$rows['doctor_department_id']);
    foreach($names as $name) {
        echo $name . ' ';
    }
    ?>
</td>

Or if you're expecting just one row:

return $query->row()->department_name;