2017-10-13 20:13
浏览 21


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?

图片转代码服务由CSDN问答提供 功能建议


 <  code> public function get_doctor_name($ doctor_id){
 $ result = $ this-&gt; db-&gt; query(“SELECT first_name,last_name from doctors where id = $ municipio_id”) - &gt; row_array(); 
 return  $ result ['first_name']; 

如何像 first_name一样返回 last_name 在同一个查询中?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanhuan6336 2017-10-13 20:15

    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.

    点赞 打赏 评论
  • douwo5710 2017-10-13 20:15

    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']
    点赞 打赏 评论

相关推荐 更多相似问题