如何从stdclass对象获取数据值?如果我使用print_r
,我会得到stdclass对象..
我的预期输出是这样的:
论文:21 剪刀:22 摇滚:12实际输出:
stdClass Object (
[player_item] =>
[total] => 1
)
stdClass Object (
[player_item] => paper
[total] => 39
)
stdClass Object (
[player_item] => rock
[total] => 32
)
stdClass Object (
[player_item] => scissors
[total] => 12
)
这是我的代码
型号:
$this->db->select('player_item, COUNT(player_item) as total');
$this->db->group_by('player_item');
$query = $this->db->get('rps');
return $query->result();
控制器:
$this->load->model('rps_model');
$data3['query']=$this->rps_model->rps_stat();
$this->load->view('rps_view',$data3);
视图:
foreach($query as $row )
{
print_r($row);
}
答案 0 :(得分:0)
在您看来:
foreach($query as $row) {
if(trim($row->player_item) != '') {
echo $row->player_item . ' : ' . $row->total . '<br/>';
}
}