我的模型有问题,如何获取以下选择查询中的所有列:
public function getAllProvince($where = array())
{
$this->db->select("id, name");
$this->db->from('target_statis');
$this->db->where($where);
$this->db->group_by("id, name");
$this->db->order_by("id");
$query = $this->db->get();
if ($query->num_rows() > 0){
return $query->result();
}
return false;
}
答案 0 :(得分:0)
尝试一下
public function getAllProvince($where = array()){
$this->db->select("*");//changed line
$this->db->from('target_statis');
$this->db->where($where);
$this->db->group_by("id,name");
$this->db->order_by("id");
$query = $this->db->get();
if ($query->num_rows() >0){
return $query->result();
}else{
return array();//changed line
}
}
答案 1 :(得分:0)
我要删除$this->db->select(column)
,因为您想获取所有列
如果您未定义$this->db->select()
,codeigniter将默认选择所有列
另外,我要删除$this->db->from()
并将表名移至$this->db->get('target_statis');
public function getAllProvince($where = array()){
$this->db->where($where);
$this->db->group_by("id,name");
$this->db->order_by("id");
$query = $this->db->get('target_statis');
if ($query->num_rows() >0){
return $query->result();
}
return FALSE;
}
答案 2 :(得分:0)
尝试此代码...
public function getAllProvince($where = array())
{
$this->db->select("*");
$this->db->from('target_statis');
$this->db->where($where);
$this->db->group_by("id, name");
$this->db->order_by("id");
$query = $this->db->get();
if ($query->num_rows() > 0){
return $query->result();
}
return false;
}