doulin2947 2011-10-22 10:42
浏览 110
已采纳

获取DB的特定字段的值

I'm trying to get a particular value of a field from the DB. But why i try to get the value it gives me the error:

Message: Undefined index: status_status_id

Part of my controller:

     function get_by_id($id = 0){


   $data['info'] = $this->Rfetch1_model->getdata_by_id($id);
   $r=$data['status_status_id'];

    if ($r==0){

         //something....
}

My model:

   function getdata_by_id($id = 0){
    $this->db->where('id',$id);

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

    return $sql->result();
}

From my understanding my model will return everything from the 'info' table where id=$id; Then why it cannot get the value of the field status_status_id.

  • 写回答

2条回答 默认 最新

  • doyhq66282 2011-10-22 10:51
    关注

    You will have to access it as:

    $r=$data['info'][0]->status_status_id;
    

    $sql->result() will return an array of row objects.

    Alternatively, you could return $sql->row() from getdata_by_id() and then access it as:

    $r=$data['info']->status_status_id;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi