无法从模型中检索代码点火器数据


codeigniter-data not retrieve from model

我已经成功地使用codeigniter制作了一个soap服务器。我想把一个数组从模型传递到控制器。但我只得到零。这是我的代码:

型号:

       $this->db->select('player_item, count(*) as total');
       $this->db->from('rps'); 
       $this->db->group_by('player_item');
       $query = $this->db->get();
       $rows = array();
       foreach ($query->result_array() as $row)
       {
          $rows[] = $row;
       }
      return $rows; 

Soap服务器:

     function get_player(){
        $CI =& get_instance();
        $CI->load->model("player");
        $data['player']=$CI->player ->get_player();
        return $data;
}

Soap客户端:

$result = $this->nusoap_client ->call('get_player');
print_r($result);

我不知道我在服务器上的代码是否正确。我刚接触SOAP。。

try to write below of this line
$data['player']=$CI->player ->get_player();
echo '<pre>'; 
print_r($data);
echo '</pre>'; 
die;

检查你是否得到了数据。如果你没有得到数据,那么var_dump($this->db->last_query());

您还可以在模型中检查是否从数据库中获取数据。

       $this->db->select('player_item, count(*) as total');
       $this->db->from('rps'); 
       $this->db->group_by('player_item');
       $query = $this->db->get();
       $rows = array();
       foreach ($query->result_array() as $row)
       {
          $rows[] = $row;
       }

echo '<pre>'; 
print_r($rows);
echo '</pre>'; 
die;
      return $rows; 

select('fields', false)函数false中添加第二个参数,跳过字段上的自动撇号,CI在mysql查询字段上自动添加撇号,所以当你使用类似count(*)的mysql函数时,它会给你mysql错误,你的查询看起来像

SELECT `player_item`, `count(*)` as `total` ......

更改

$this->db->select('player_item, count(*) as total');

 $this->db->select('`player_item`, count(*) as `total`', false);