Diasline
Diasline

Reputation: 635

Return two rows from database using codeigniter

This query works as I want but only returns one value.

public function get_doctor_name($doctor_id)  {
  $result = $this->db->query("SELECT first_name, last_name from doctors where id= $municipio_id")->row_array();
  return $result['first_name'];
}

How to return the last_name as I did for first_name in the same query?

Upvotes: 0

Views: 45

Answers (2)

azbatuk
azbatuk

Reputation: 293

Your query is actually correct.

However, you can use return $result->result_array(); to get an array of all fields, first_name, last_name etc.

Upvotes: 1

u_mulder
u_mulder

Reputation: 54796

You can return array:

return $result;

You can return a string, for example:

return $result['first_name'] . ' ' . $result['last_name'];

You can return array with specific keys that you define:

return [
    'f_name' => $result['first_name'], 
    'l_name' => $result['last_name']
];

Upvotes: 2

Related Questions