我想拉出一個列的數據庫,很簡單吧?我正在使用codeigniter的活動記錄。數據庫查詢codeigniter活動記錄returing對象
我的型號功能
public function getcolumn($field, $table, $kfield, $key)
{
$this->db->select($field);
$this->db->from($table);
$this->db->where($kfield, $key);
$query = $this->db->get();
$results = $query->result();
return $results;
}
我的控制器具有:
public function users()
{
$body['handle'] = $this->admin->getcolumn('handle', 'users', 'userid', $userid)
$this->load->view('template/header');
$this->load->view('admin/users', $body);
$this->load->view('template/footer');
}
現在當我的print_r,我認爲,變量I得到「陣列([0] => stdClass的對象([把手] => Zanigade))「
因爲我試圖用這個函數作爲一個全局的」抓取和去「函數而不寫一大堆函數,爲什麼它不會只返回這個名字?我究竟做錯了什麼?我一直在玩輸出3小時,我知道這是一個愚蠢的簡單的解決方案,我只是錯過了標記。
任何幫助將不勝感激。
行,所以我意識到,改變我的模型函數返回$結果[0];允許我通過使用$ handle-> handle來拉我的選擇.....有沒有辦法讓它處理只是答案而不必 - > columnName?我覺得有一種方法,雖然我可能會誤 – bdon
爲陣列,你可以在模型中使用result_array而不是結果 –