请看看这两个功能
function _getColumn($table, $column, $where = array()) {
$this->db->select($column);
$q = $this->db->get_where($table, $where);
return ($q->num_rows() > 0) ? $q->result()[0]->$column : FALSE;
}
//after calling this function your result is as follows
var_dump($this->model_name->_getColumn('people', 'name', array('personID' => '1')));
//output
//string(6) "Maxcot" //or BOOLEAN(FALSE)
//also please note that it can not handle as "$column" parameter this input = "id, name"
第二个功能是获取更多列
function _getColumns($table, $column, $where = array()) {
$this->db->select($column);
$this->db->where($where);
$q = $this->db->get($table);
return ($q->num_rows() > 0) ? $q->result()[0] : FALSE;
}
//after calling function like this
$person_info = $this->model_name->_getColumn('people', 'name, address, phone', array('personID' => '1'));
//you can access table columns like this (also check if $person_info is not FALSE)
$person_info->name;// ->address, ->phone