Codeigniter $this->db->get(), how do I return values for a specific row?

前端 未结 5 1397
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-07 19:19

Say I have a database table with three columns: ID, Name, and Age. I need to find the user with a specific (unique) ID, and then return the age. Currently, I am using the fo

5条回答
  •  忘掉有多难
    2020-12-07 19:58

    Accessing a single row

    //Result as an Object
    $result = $this->db->select('age')->from('my_users_table')->where('id', '3')->limit(1)->get()->row();
    echo $result->age;
    
    //Result as an Array
    $result = $this->db->select('age')->from('my_users_table')->where('id', '3')->limit(1)->get()->row_array();
    echo $result['age'];
    

提交回复
热议问题